{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "/Users/hufox/scGCN/scGCN\r\n"
     ]
    }
   ],
   "source": [
    "!pwd"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "train.py\n",
    "## 1.Load data\n",
    "adj, features, labels_binary_train, labels_binary_val, labels_binary_test, train_mask, pred_mask, val_mask, test_mask, new_label, true_label, index_guide = load_data(\n",
    "    FLAGS.dataset,rgraph=FLAGS.graph)\n",
    "## 2.load_data方法\n",
    "scGCN/utils.py\n",
    "def load_data(datadir,rgraph=True):\n",
    "    input_data(datadir,Rgraph=rgraph)\n",
    "    PIK = \"{}/datasets.dat\".format(datadir)\n",
    "    with open(PIK, \"rb\") as f:\n",
    "        objects = pkl.load(f)\n",
    "\n",
    "    data_train1, data_test1, data_val1, label_train1, label_test1, label_val1, lab_data2, lab_label2, types = tuple(\n",
    "        objects)\n",
    "## 3.input_data(datadir,Rgraph=rgraph)\n",
    "scGCN/data.py\n",
    "#' data preperation\n",
    "def input_data(DataDir,Rgraph=True):\n",
    "    if Rgraph==False:\n",
    "        graph_construct(outputdir='process_data')\n",
    "     \n",
    "    DataPath1 = '{}/Data1.csv'.format(DataDir)\n",
    "    DataPath2 = '{}/Data2.csv'.format(DataDir)\n",
    "    LabelsPath1 = '{}/Label1.csv'.format(DataDir)\n",
    "    LabelsPath2 = '{}/Label2.csv'.format(DataDir)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "import os\n",
    "import numpy as np\n",
    "import random\n",
    "import pandas as pd\n",
    "import time as tm\n",
    "from operator import itemgetter\n",
    "from sklearn.model_selection import train_test_split\n",
    "import pickle as pkl\n",
    "import scipy.sparse\n",
    "from graph import *"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "DataPath1 = '/Users/hufox/scGCN/scGCN/input/Data1.csv'\n",
    "DataPath2 = '/Users/hufox/scGCN/scGCN/input/Data2.csv'\n",
    "LabelsPath1 = '/Users/hufox/scGCN/scGCN/input/Label1.csv'\n",
    "LabelsPath2 = '/Users/hufox/scGCN/scGCN/input/Label2.csv'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>APOE</th>\n",
       "      <th>B2M</th>\n",
       "      <th>CD53</th>\n",
       "      <th>CD74</th>\n",
       "      <th>CD93</th>\n",
       "      <th>CDH5</th>\n",
       "      <th>CORO1A</th>\n",
       "      <th>CSF1R</th>\n",
       "      <th>CTSS</th>\n",
       "      <th>EGFL7</th>\n",
       "      <th>...</th>\n",
       "      <th>MGAT4A</th>\n",
       "      <th>AGAP1</th>\n",
       "      <th>SKAP1</th>\n",
       "      <th>FXYD1</th>\n",
       "      <th>NFIA</th>\n",
       "      <th>OLFM3</th>\n",
       "      <th>AMPD2</th>\n",
       "      <th>LZTS2</th>\n",
       "      <th>RGL1</th>\n",
       "      <th>BTG2</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>mouse1_lib1.final_cell_0001</th>\n",
       "      <td>0</td>\n",
       "      <td>4</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>mouse1_lib1.final_cell_0002</th>\n",
       "      <td>0</td>\n",
       "      <td>6</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>mouse1_lib1.final_cell_0003</th>\n",
       "      <td>1</td>\n",
       "      <td>5</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>mouse1_lib1.final_cell_0005</th>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>mouse1_lib1.final_cell_0006</th>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5 rows × 2000 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                             APOE  B2M  CD53  CD74  CD93  CDH5  CORO1A  CSF1R  \\\n",
       "mouse1_lib1.final_cell_0001     0    4     0     0     0     0       0      0   \n",
       "mouse1_lib1.final_cell_0002     0    6     0     0     0     0       0      0   \n",
       "mouse1_lib1.final_cell_0003     1    5     0     0     0     0       0      0   \n",
       "mouse1_lib1.final_cell_0005     0    1     0     0     0     0       0      0   \n",
       "mouse1_lib1.final_cell_0006     0    2     0     0     0     0       0      0   \n",
       "\n",
       "                             CTSS  EGFL7  ...  MGAT4A  AGAP1  SKAP1  FXYD1  \\\n",
       "mouse1_lib1.final_cell_0001     0      0  ...       0      2      0      0   \n",
       "mouse1_lib1.final_cell_0002     0      0  ...       0      0      0      0   \n",
       "mouse1_lib1.final_cell_0003     0      0  ...       0      0      0      0   \n",
       "mouse1_lib1.final_cell_0005     0      0  ...       0      0      0      0   \n",
       "mouse1_lib1.final_cell_0006     0      0  ...       0      2      0      0   \n",
       "\n",
       "                             NFIA  OLFM3  AMPD2  LZTS2  RGL1  BTG2  \n",
       "mouse1_lib1.final_cell_0001     0      0      0      0     0     1  \n",
       "mouse1_lib1.final_cell_0002     0      0      0      0     0     3  \n",
       "mouse1_lib1.final_cell_0003     0      0      0      0     0     3  \n",
       "mouse1_lib1.final_cell_0005     0      0      2      0     0     3  \n",
       "mouse1_lib1.final_cell_0006     0      0      2      1     0     2  \n",
       "\n",
       "[5 rows x 2000 columns]"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    " #' read the data\n",
    "# mouse数据\n",
    "data1 = pd.read_csv(DataPath1, index_col=0, sep=',')\n",
    "data1.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\n",
      "Index: 1841 entries, mouse1_lib1.final_cell_0001 to mouse2_lib3.final_cell_0395\n",
      "Columns: 2000 entries, APOE to BTG2\n",
      "dtypes: int64(2000)\n",
      "memory usage: 28.1+ MB\n"
     ]
    }
   ],
   "source": [
    "data1.info()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>APOE</th>\n",
       "      <th>B2M</th>\n",
       "      <th>CD53</th>\n",
       "      <th>CD74</th>\n",
       "      <th>CD93</th>\n",
       "      <th>CDH5</th>\n",
       "      <th>CORO1A</th>\n",
       "      <th>CSF1R</th>\n",
       "      <th>CTSS</th>\n",
       "      <th>EGFL7</th>\n",
       "      <th>...</th>\n",
       "      <th>MGAT4A</th>\n",
       "      <th>AGAP1</th>\n",
       "      <th>SKAP1</th>\n",
       "      <th>FXYD1</th>\n",
       "      <th>NFIA</th>\n",
       "      <th>OLFM3</th>\n",
       "      <th>AMPD2</th>\n",
       "      <th>LZTS2</th>\n",
       "      <th>RGL1</th>\n",
       "      <th>BTG2</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>human1_lib1.final_cell_0007</th>\n",
       "      <td>0</td>\n",
       "      <td>14</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>4</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>human1_lib1.final_cell_0013</th>\n",
       "      <td>0</td>\n",
       "      <td>13</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>human1_lib1.final_cell_0014</th>\n",
       "      <td>0</td>\n",
       "      <td>11</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>human1_lib1.final_cell_0015</th>\n",
       "      <td>0</td>\n",
       "      <td>6</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>...</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>human1_lib1.final_cell_0017</th>\n",
       "      <td>0</td>\n",
       "      <td>6</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5 rows × 2000 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                             APOE  B2M  CD53  CD74  CD93  CDH5  CORO1A  CSF1R  \\\n",
       "human1_lib1.final_cell_0007     0   14     0     0     0     0       0      0   \n",
       "human1_lib1.final_cell_0013     0   13     0     1     0     0       0      0   \n",
       "human1_lib1.final_cell_0014     0   11     0     0     0     0       0      0   \n",
       "human1_lib1.final_cell_0015     0    6     0     0     0     0       0      0   \n",
       "human1_lib1.final_cell_0017     0    6     0     0     0     0       0      0   \n",
       "\n",
       "                             CTSS  EGFL7  ...  MGAT4A  AGAP1  SKAP1  FXYD1  \\\n",
       "human1_lib1.final_cell_0007     0      0  ...       4      0      0      0   \n",
       "human1_lib1.final_cell_0013     0      0  ...       0      0      0      0   \n",
       "human1_lib1.final_cell_0014     0      0  ...       0      1      0      0   \n",
       "human1_lib1.final_cell_0015     0      1  ...       1      1      0      0   \n",
       "human1_lib1.final_cell_0017     0      0  ...       0      0      0      0   \n",
       "\n",
       "                             NFIA  OLFM3  AMPD2  LZTS2  RGL1  BTG2  \n",
       "human1_lib1.final_cell_0007     0      0      2      0     0     0  \n",
       "human1_lib1.final_cell_0013     0      0      3      1     0     0  \n",
       "human1_lib1.final_cell_0014     0      0      1      2     0     8  \n",
       "human1_lib1.final_cell_0015     1      0      0      0     0     0  \n",
       "human1_lib1.final_cell_0017     0      0      0      0     0     0  \n",
       "\n",
       "[5 rows x 2000 columns]"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# human 数据\n",
    "data2 = pd.read_csv(DataPath2, index_col=0, sep=',')\n",
    "data2.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\n",
      "Index: 7264 entries, human1_lib1.final_cell_0007 to human4_lib3.final_cell_0701\n",
      "Columns: 2000 entries, APOE to BTG2\n",
      "dtypes: int64(2000)\n",
      "memory usage: 110.9+ MB\n"
     ]
    }
   ],
   "source": [
    "data2.info()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>type</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>beta</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>ductal</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>delta</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>delta</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>beta</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     type\n",
       "0    beta\n",
       "1  ductal\n",
       "2   delta\n",
       "3   delta\n",
       "4    beta"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "lab_label1 = pd.read_csv(LabelsPath1, header=0, index_col=False, sep=',')\n",
    "lab_label1.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\n",
      "RangeIndex: 1841 entries, 0 to 1840\n",
      "Data columns (total 1 columns):\n",
      " #   Column  Non-Null Count  Dtype \n",
      "---  ------  --------------  ----- \n",
      " 0   type    1841 non-null   object\n",
      "dtypes: object(1)\n",
      "memory usage: 14.5+ KB\n"
     ]
    }
   ],
   "source": [
    "lab_label1.info()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>type</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>beta</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>delta</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>delta</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>beta</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>beta</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    type\n",
       "0   beta\n",
       "1  delta\n",
       "2  delta\n",
       "3   beta\n",
       "4   beta"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "lab_label2 = pd.read_csv(LabelsPath2, header=0, index_col=False, sep=',')\n",
    "lab_label2.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>APOE</th>\n",
       "      <th>B2M</th>\n",
       "      <th>CD53</th>\n",
       "      <th>CD74</th>\n",
       "      <th>CD93</th>\n",
       "      <th>CDH5</th>\n",
       "      <th>CORO1A</th>\n",
       "      <th>CSF1R</th>\n",
       "      <th>CTSS</th>\n",
       "      <th>EGFL7</th>\n",
       "      <th>...</th>\n",
       "      <th>MGAT4A</th>\n",
       "      <th>AGAP1</th>\n",
       "      <th>SKAP1</th>\n",
       "      <th>FXYD1</th>\n",
       "      <th>NFIA</th>\n",
       "      <th>OLFM3</th>\n",
       "      <th>AMPD2</th>\n",
       "      <th>LZTS2</th>\n",
       "      <th>RGL1</th>\n",
       "      <th>BTG2</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "      <td>4</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>0</td>\n",
       "      <td>6</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1</td>\n",
       "      <td>5</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5 rows × 2000 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "   APOE  B2M  CD53  CD74  CD93  CDH5  CORO1A  CSF1R  CTSS  EGFL7  ...  MGAT4A  \\\n",
       "0     0    4     0     0     0     0       0      0     0      0  ...       0   \n",
       "1     0    6     0     0     0     0       0      0     0      0  ...       0   \n",
       "2     1    5     0     0     0     0       0      0     0      0  ...       0   \n",
       "3     0    1     0     0     0     0       0      0     0      0  ...       0   \n",
       "4     0    2     0     0     0     0       0      0     0      0  ...       0   \n",
       "\n",
       "   AGAP1  SKAP1  FXYD1  NFIA  OLFM3  AMPD2  LZTS2  RGL1  BTG2  \n",
       "0      2      0      0     0      0      0      0     0     1  \n",
       "1      0      0      0     0      0      0      0     0     3  \n",
       "2      0      0      0     0      0      0      0     0     3  \n",
       "3      0      0      0     0      0      2      0     0     3  \n",
       "4      2      0      0     0      0      2      1     0     2  \n",
       "\n",
       "[5 rows x 2000 columns]"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#重置索引,将细胞名称换成0，1，2，3，4....索引\n",
    "lab_data1 = data1.reset_index(drop=True)  #.transpose()\n",
    "lab_data1.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>APOE</th>\n",
       "      <th>B2M</th>\n",
       "      <th>CD53</th>\n",
       "      <th>CD74</th>\n",
       "      <th>CD93</th>\n",
       "      <th>CDH5</th>\n",
       "      <th>CORO1A</th>\n",
       "      <th>CSF1R</th>\n",
       "      <th>CTSS</th>\n",
       "      <th>EGFL7</th>\n",
       "      <th>...</th>\n",
       "      <th>MGAT4A</th>\n",
       "      <th>AGAP1</th>\n",
       "      <th>SKAP1</th>\n",
       "      <th>FXYD1</th>\n",
       "      <th>NFIA</th>\n",
       "      <th>OLFM3</th>\n",
       "      <th>AMPD2</th>\n",
       "      <th>LZTS2</th>\n",
       "      <th>RGL1</th>\n",
       "      <th>BTG2</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "      <td>14</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>4</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>0</td>\n",
       "      <td>13</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>0</td>\n",
       "      <td>11</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>0</td>\n",
       "      <td>6</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>...</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>0</td>\n",
       "      <td>6</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5 rows × 2000 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "   APOE  B2M  CD53  CD74  CD93  CDH5  CORO1A  CSF1R  CTSS  EGFL7  ...  MGAT4A  \\\n",
       "0     0   14     0     0     0     0       0      0     0      0  ...       4   \n",
       "1     0   13     0     1     0     0       0      0     0      0  ...       0   \n",
       "2     0   11     0     0     0     0       0      0     0      0  ...       0   \n",
       "3     0    6     0     0     0     0       0      0     0      1  ...       1   \n",
       "4     0    6     0     0     0     0       0      0     0      0  ...       0   \n",
       "\n",
       "   AGAP1  SKAP1  FXYD1  NFIA  OLFM3  AMPD2  LZTS2  RGL1  BTG2  \n",
       "0      0      0      0     0      0      2      0     0     0  \n",
       "1      0      0      0     0      0      3      1     0     0  \n",
       "2      1      0      0     0      0      1      2     0     8  \n",
       "3      1      0      0     1      0      0      0     0     0  \n",
       "4      0      0      0     0      0      0      0     0     0  \n",
       "\n",
       "[5 rows x 2000 columns]"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "lab_data2 = data2.reset_index(drop=True)  #.transpose()\n",
    "lab_data2.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>type</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>beta</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>ductal</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>delta</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>delta</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>beta</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     type\n",
       "0    beta\n",
       "1  ductal\n",
       "2   delta\n",
       "3   delta\n",
       "4    beta"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#给标签列指定列名称 type\n",
    "lab_label1.columns = ['type']\n",
    "lab_label1.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>type</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>beta</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>delta</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>delta</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>beta</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>beta</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    type\n",
       "0   beta\n",
       "1  delta\n",
       "2  delta\n",
       "3   beta\n",
       "4   beta"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "lab_label2.columns = ['type']\n",
    "lab_label2.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['alpha',\n",
       " 'beta',\n",
       " 'delta',\n",
       " 'ductal',\n",
       " 'endothelial',\n",
       " 'gamma',\n",
       " 'macrophage',\n",
       " 'quiescent_stellate']"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#获取细胞类型list，np.unique去除重复值，目的是为了后面选取每一种数据\n",
    "types = np.unique(lab_label1['type']).tolist()\n",
    "types"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [],
   "source": [
    "#设置随机种子，确保每次实验选取数据一样，同时设置p_data，p_label用于存放每一种类型的选取的细胞数据，使用random.sample(range(0, len(tem_index)), num_to_select)\n",
    "#对在指定范围内进行数据采样\n",
    "random.seed(123)\n",
    "p_data = []\n",
    "p_label = []"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {},
   "outputs": [],
   "source": [
    "for i in types:\n",
    "        tem_index = lab_label1[lab_label1['type'] == i].index\n",
    "        tem_label = lab_label1[lab_label1['type'] == i]\n",
    "        tem_data = lab_data1.iloc[tem_index]\n",
    "        num_to_select = len(tem_data)\n",
    "        random_items = random.sample(range(0, len(tem_index)), num_to_select)\n",
    "        # print(random_items)\n",
    "        sub_data = tem_data.iloc[random_items]\n",
    "        sub_label = tem_label.iloc[random_items]\n",
    "        # print((sub_data.index == sub_label.index).all())\n",
    "        p_data.append(sub_data)\n",
    "        p_label.append(sub_label)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>APOE</th>\n",
       "      <th>B2M</th>\n",
       "      <th>CD53</th>\n",
       "      <th>CD74</th>\n",
       "      <th>CD93</th>\n",
       "      <th>CDH5</th>\n",
       "      <th>CORO1A</th>\n",
       "      <th>CSF1R</th>\n",
       "      <th>CTSS</th>\n",
       "      <th>EGFL7</th>\n",
       "      <th>...</th>\n",
       "      <th>MGAT4A</th>\n",
       "      <th>AGAP1</th>\n",
       "      <th>SKAP1</th>\n",
       "      <th>FXYD1</th>\n",
       "      <th>NFIA</th>\n",
       "      <th>OLFM3</th>\n",
       "      <th>AMPD2</th>\n",
       "      <th>LZTS2</th>\n",
       "      <th>RGL1</th>\n",
       "      <th>BTG2</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>852</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1143</th>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>880</th>\n",
       "      <td>0</td>\n",
       "      <td>12</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1342</th>\n",
       "      <td>0</td>\n",
       "      <td>5</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1793</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1561</th>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1048</th>\n",
       "      <td>0</td>\n",
       "      <td>6</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1668</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1660</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1151</th>\n",
       "      <td>0</td>\n",
       "      <td>4</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>191 rows × 2000 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "      APOE  B2M  CD53  CD74  CD93  CDH5  CORO1A  CSF1R  CTSS  EGFL7  ...  \\\n",
       "852      0    0     0     0     0     0       0      0     0      0  ...   \n",
       "1143     0    1     0     0     0     0       0      0     0      0  ...   \n",
       "880      0   12     0     0     0     0       0      0     0      0  ...   \n",
       "1342     0    5     0     0     0     0       0      0     0      0  ...   \n",
       "1793     0    0     0     0     0     0       0      0     0      0  ...   \n",
       "...    ...  ...   ...   ...   ...   ...     ...    ...   ...    ...  ...   \n",
       "1561     0    1     0     0     0     0       0      0     0      0  ...   \n",
       "1048     0    6     0     0     0     0       0      0     0      0  ...   \n",
       "1668     0    0     0     0     0     0       0      0     0      0  ...   \n",
       "1660     0    0     0     0     0     0       0      0     0      0  ...   \n",
       "1151     0    4     0     0     0     0       0      0     0      0  ...   \n",
       "\n",
       "      MGAT4A  AGAP1  SKAP1  FXYD1  NFIA  OLFM3  AMPD2  LZTS2  RGL1  BTG2  \n",
       "852        0      3      0      0     0      0      0      2     0     6  \n",
       "1143       0      0      0      0     0      0      0      0     0     1  \n",
       "880        0      0      0      0     0      0      0      0     0     0  \n",
       "1342       2      0      0      0     0      0      0      0     0     2  \n",
       "1793       0      0      0      0     0      0      0      0     0     0  \n",
       "...      ...    ...    ...    ...   ...    ...    ...    ...   ...   ...  \n",
       "1561       1      0      0      0     0      0      0      0     0     0  \n",
       "1048       0      1      0      0     0      0      0      0     0     2  \n",
       "1668       0      0      0      0     0      0      0      0     0     3  \n",
       "1660       0      1      0      0     0      0      0      0     0     0  \n",
       "1151       0      0      0      0     1      0      1      1     0    10  \n",
       "\n",
       "[191 rows x 2000 columns]"
      ]
     },
     "execution_count": 45,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#p_data 存放8种类型的细胞列表,p_data[0]存放的是alpha类型的所有细胞数据\n",
    "p_data[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>type</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>852</th>\n",
       "      <td>alpha</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1143</th>\n",
       "      <td>alpha</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>880</th>\n",
       "      <td>alpha</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1342</th>\n",
       "      <td>alpha</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1793</th>\n",
       "      <td>alpha</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1561</th>\n",
       "      <td>alpha</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1048</th>\n",
       "      <td>alpha</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1668</th>\n",
       "      <td>alpha</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1660</th>\n",
       "      <td>alpha</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1151</th>\n",
       "      <td>alpha</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>191 rows × 1 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "       type\n",
       "852   alpha\n",
       "1143  alpha\n",
       "880   alpha\n",
       "1342  alpha\n",
       "1793  alpha\n",
       "...     ...\n",
       "1561  alpha\n",
       "1048  alpha\n",
       "1668  alpha\n",
       "1660  alpha\n",
       "1151  alpha\n",
       "\n",
       "[191 rows x 1 columns]"
      ]
     },
     "execution_count": 46,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "p_label[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "metadata": {},
   "outputs": [],
   "source": [
    "#' split data to training, test, valdiaton sets\n",
    "# 将数据和标签分为训练集、测试集、验证集\n",
    "data_train = []\n",
    "data_test = []\n",
    "data_val = []\n",
    "label_train = []\n",
    "label_test = []\n",
    "label_val = []"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "True\n",
      "True\n",
      "True\n",
      "True\n",
      "True\n",
      "True\n",
      "True\n",
      "True\n",
      "True\n",
      "True\n",
      "True\n",
      "True\n",
      "True\n",
      "True\n",
      "True\n",
      "True\n",
      "True\n",
      "True\n",
      "True\n",
      "True\n",
      "True\n",
      "True\n",
      "True\n",
      "True\n"
     ]
    }
   ],
   "source": [
    "for i in range(0, len(p_data)):\n",
    "        #测试集取10%，训练集90%\n",
    "        temD_train, temd_test, temL_train, teml_test = train_test_split(\n",
    "            p_data[i], p_label[i], test_size=0.1, random_state=1)\n",
    "        #再从训练集里取10%作为验证集\n",
    "        temd_train, temd_val, teml_train, teml_val = train_test_split(\n",
    "            temD_train, temL_train, test_size=0.1, random_state=1)\n",
    "        print((temd_train.index == teml_train.index).all())\n",
    "        print((temd_test.index == teml_test.index).all())\n",
    "        print((temd_val.index == teml_val.index).all())\n",
    "        data_train.append(temd_train)\n",
    "        label_train.append(teml_train)\n",
    "        data_test.append(temd_test)\n",
    "        label_test.append(teml_test)\n",
    "        data_val.append(temd_val)\n",
    "        label_val.append(teml_val)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>APOE</th>\n",
       "      <th>B2M</th>\n",
       "      <th>CD53</th>\n",
       "      <th>CD74</th>\n",
       "      <th>CD93</th>\n",
       "      <th>CDH5</th>\n",
       "      <th>CORO1A</th>\n",
       "      <th>CSF1R</th>\n",
       "      <th>CTSS</th>\n",
       "      <th>EGFL7</th>\n",
       "      <th>...</th>\n",
       "      <th>MGAT4A</th>\n",
       "      <th>AGAP1</th>\n",
       "      <th>SKAP1</th>\n",
       "      <th>FXYD1</th>\n",
       "      <th>NFIA</th>\n",
       "      <th>OLFM3</th>\n",
       "      <th>AMPD2</th>\n",
       "      <th>LZTS2</th>\n",
       "      <th>RGL1</th>\n",
       "      <th>BTG2</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>137</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1582</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1392</th>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>992</th>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>952</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>839</th>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>12</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1543</th>\n",
       "      <td>0</td>\n",
       "      <td>10</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>974</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1143</th>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1382</th>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>8</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>153 rows × 2000 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "      APOE  B2M  CD53  CD74  CD93  CDH5  CORO1A  CSF1R  CTSS  EGFL7  ...  \\\n",
       "137      0    0     0     0     0     0       0      0     0      0  ...   \n",
       "1582     0    0     0     0     0     0       0      0     0      0  ...   \n",
       "1392     0    3     0     0     0     0       0      0     0      0  ...   \n",
       "992      0    1     0     0     0     0       0      0     0      0  ...   \n",
       "952      0    0     0     1     0     0       0      0     0      0  ...   \n",
       "...    ...  ...   ...   ...   ...   ...     ...    ...   ...    ...  ...   \n",
       "839      0    3     0     0     0     0       0      0     0      0  ...   \n",
       "1543     0   10     0     0     0     0       0      0     1      0  ...   \n",
       "974      0    0     0     0     0     0       0      0     0      0  ...   \n",
       "1143     0    1     0     0     0     0       0      0     0      0  ...   \n",
       "1382     0    1     0     0     0     0       0      0     0      0  ...   \n",
       "\n",
       "      MGAT4A  AGAP1  SKAP1  FXYD1  NFIA  OLFM3  AMPD2  LZTS2  RGL1  BTG2  \n",
       "137        1      0      0      0     0      0      0      1     0     0  \n",
       "1582       0      0      0      0     0      0      0      0     0     0  \n",
       "1392       0      0      0      0     0      0      0      0     0     0  \n",
       "992        0      0      0      0     0      0      0      0     0     0  \n",
       "952        0      0      0      0     0      0      1      0     0     1  \n",
       "...      ...    ...    ...    ...   ...    ...    ...    ...   ...   ...  \n",
       "839        0      0      0      0     0      0      0      1     0    12  \n",
       "1543       0      0      0      0     0      0      0      1     0     5  \n",
       "974        0      0      0      0     0      0      1      0     0     3  \n",
       "1143       0      0      0      0     0      0      0      0     0     1  \n",
       "1382       0      0      1      0     0      0      0      0     0     8  \n",
       "\n",
       "[153 rows x 2000 columns]"
      ]
     },
     "execution_count": 54,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data_train[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>type</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>137</th>\n",
       "      <td>alpha</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1582</th>\n",
       "      <td>alpha</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1392</th>\n",
       "      <td>alpha</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>992</th>\n",
       "      <td>alpha</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>952</th>\n",
       "      <td>alpha</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>839</th>\n",
       "      <td>alpha</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1543</th>\n",
       "      <td>alpha</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>974</th>\n",
       "      <td>alpha</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1143</th>\n",
       "      <td>alpha</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1382</th>\n",
       "      <td>alpha</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>153 rows × 1 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "       type\n",
       "137   alpha\n",
       "1582  alpha\n",
       "1392  alpha\n",
       "992   alpha\n",
       "952   alpha\n",
       "...     ...\n",
       "839   alpha\n",
       "1543  alpha\n",
       "974   alpha\n",
       "1143  alpha\n",
       "1382  alpha\n",
       "\n",
       "[153 rows x 1 columns]"
      ]
     },
     "execution_count": 55,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "label_train[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>APOE</th>\n",
       "      <th>B2M</th>\n",
       "      <th>CD53</th>\n",
       "      <th>CD74</th>\n",
       "      <th>CD93</th>\n",
       "      <th>CDH5</th>\n",
       "      <th>CORO1A</th>\n",
       "      <th>CSF1R</th>\n",
       "      <th>CTSS</th>\n",
       "      <th>EGFL7</th>\n",
       "      <th>...</th>\n",
       "      <th>MGAT4A</th>\n",
       "      <th>AGAP1</th>\n",
       "      <th>SKAP1</th>\n",
       "      <th>FXYD1</th>\n",
       "      <th>NFIA</th>\n",
       "      <th>OLFM3</th>\n",
       "      <th>AMPD2</th>\n",
       "      <th>LZTS2</th>\n",
       "      <th>RGL1</th>\n",
       "      <th>BTG2</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>887</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>989</th>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1349</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1538</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1353</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1606</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1166</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1050</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>512</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1084</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1597</th>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1728</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1012</th>\n",
       "      <td>0</td>\n",
       "      <td>4</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1256</th>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1561</th>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1149</th>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1137</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1434</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1793</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1534</th>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>20 rows × 2000 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "      APOE  B2M  CD53  CD74  CD93  CDH5  CORO1A  CSF1R  CTSS  EGFL7  ...  \\\n",
       "887      0    0     0     0     0     0       0      0     0      0  ...   \n",
       "989      0    1     0     0     0     0       0      0     0      0  ...   \n",
       "1349     0    0     0     0     0     0       0      0     0      0  ...   \n",
       "1538     0    0     0     0     0     0       0      0     0      0  ...   \n",
       "1353     0    0     0     0     0     0       0      0     0      0  ...   \n",
       "1606     0    0     0     0     0     0       0      0     0      0  ...   \n",
       "1166     0    0     0     0     0     0       0      0     0      0  ...   \n",
       "1050     0    0     0     0     0     0       0      0     0      0  ...   \n",
       "512      0    0     0     0     0     0       0      0     0      0  ...   \n",
       "1084     0    0     0     0     0     0       0      0     0      0  ...   \n",
       "1597     0    1     0     0     0     0       0      0     0      0  ...   \n",
       "1728     0    0     0     0     0     0       0      0     0      0  ...   \n",
       "1012     0    4     0     0     0     0       0      0     0      0  ...   \n",
       "1256     0    2     0     0     0     0       0      0     0      0  ...   \n",
       "1561     0    1     0     0     0     0       0      0     0      0  ...   \n",
       "1149     0    3     0     0     0     0       0      0     0      0  ...   \n",
       "1137     0    0     0     0     0     0       0      0     0      0  ...   \n",
       "1434     0    0     0     0     0     0       0      0     0      0  ...   \n",
       "1793     0    0     0     0     0     0       0      0     0      0  ...   \n",
       "1534     0    1     0     0     0     0       0      0     0      0  ...   \n",
       "\n",
       "      MGAT4A  AGAP1  SKAP1  FXYD1  NFIA  OLFM3  AMPD2  LZTS2  RGL1  BTG2  \n",
       "887        0      0      0      0     1      0      0      0     0     1  \n",
       "989        0      1      0      0     0      0      0      0     0     0  \n",
       "1349       0      0      0      0     0      0      0      1     0     5  \n",
       "1538       0      1      1      0     0      0      0      1     0     1  \n",
       "1353       0      0      0      0     0      0      0      0     0     1  \n",
       "1606       0      0      0      0     0      0      0      0     0     8  \n",
       "1166       0      1      0      0     0      0      0      0     1     3  \n",
       "1050       0      0      0      0     0      0      0      0     0     0  \n",
       "512        0      0      1      0     0      0      0      0     0     0  \n",
       "1084       0      0      0      0     0      0      0      0     0     2  \n",
       "1597       0      0      0      0     0      0      0      0     2     5  \n",
       "1728       0      0      0      0     0      0      1      0     0     2  \n",
       "1012       0      0      0      0     0      0      0      0     0     0  \n",
       "1256       0      2      0      0     0      0      0      0     0     1  \n",
       "1561       1      0      0      0     0      0      0      0     0     0  \n",
       "1149       0      0      0      0     0      0      0      0     1     0  \n",
       "1137       0      0      1      0     1      0      1      0     0     6  \n",
       "1434       0      0      0      0     0      0      0      0     0     0  \n",
       "1793       0      0      0      0     0      0      0      0     0     0  \n",
       "1534       0      1      0      0     0      0      0      0     0     3  \n",
       "\n",
       "[20 rows x 2000 columns]"
      ]
     },
     "execution_count": 56,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data_test[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>type</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>887</th>\n",
       "      <td>alpha</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>989</th>\n",
       "      <td>alpha</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1349</th>\n",
       "      <td>alpha</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1538</th>\n",
       "      <td>alpha</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1353</th>\n",
       "      <td>alpha</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1606</th>\n",
       "      <td>alpha</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1166</th>\n",
       "      <td>alpha</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1050</th>\n",
       "      <td>alpha</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>512</th>\n",
       "      <td>alpha</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1084</th>\n",
       "      <td>alpha</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1597</th>\n",
       "      <td>alpha</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1728</th>\n",
       "      <td>alpha</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1012</th>\n",
       "      <td>alpha</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1256</th>\n",
       "      <td>alpha</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1561</th>\n",
       "      <td>alpha</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1149</th>\n",
       "      <td>alpha</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1137</th>\n",
       "      <td>alpha</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1434</th>\n",
       "      <td>alpha</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1793</th>\n",
       "      <td>alpha</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1534</th>\n",
       "      <td>alpha</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "       type\n",
       "887   alpha\n",
       "989   alpha\n",
       "1349  alpha\n",
       "1538  alpha\n",
       "1353  alpha\n",
       "1606  alpha\n",
       "1166  alpha\n",
       "1050  alpha\n",
       "512   alpha\n",
       "1084  alpha\n",
       "1597  alpha\n",
       "1728  alpha\n",
       "1012  alpha\n",
       "1256  alpha\n",
       "1561  alpha\n",
       "1149  alpha\n",
       "1137  alpha\n",
       "1434  alpha\n",
       "1793  alpha\n",
       "1534  alpha"
      ]
     },
     "execution_count": 57,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "label_test[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 59,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>APOE</th>\n",
       "      <th>B2M</th>\n",
       "      <th>CD53</th>\n",
       "      <th>CD74</th>\n",
       "      <th>CD93</th>\n",
       "      <th>CDH5</th>\n",
       "      <th>CORO1A</th>\n",
       "      <th>CSF1R</th>\n",
       "      <th>CTSS</th>\n",
       "      <th>EGFL7</th>\n",
       "      <th>...</th>\n",
       "      <th>MGAT4A</th>\n",
       "      <th>AGAP1</th>\n",
       "      <th>SKAP1</th>\n",
       "      <th>FXYD1</th>\n",
       "      <th>NFIA</th>\n",
       "      <th>OLFM3</th>\n",
       "      <th>AMPD2</th>\n",
       "      <th>LZTS2</th>\n",
       "      <th>RGL1</th>\n",
       "      <th>BTG2</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>137</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1582</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1392</th>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>992</th>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>952</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>651</th>\n",
       "      <td>0</td>\n",
       "      <td>10</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1092</th>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>585</th>\n",
       "      <td>0</td>\n",
       "      <td>5</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1082</th>\n",
       "      <td>0</td>\n",
       "      <td>8</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>703</th>\n",
       "      <td>0</td>\n",
       "      <td>5</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>1483 rows × 2000 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "      APOE  B2M  CD53  CD74  CD93  CDH5  CORO1A  CSF1R  CTSS  EGFL7  ...  \\\n",
       "137      0    0     0     0     0     0       0      0     0      0  ...   \n",
       "1582     0    0     0     0     0     0       0      0     0      0  ...   \n",
       "1392     0    3     0     0     0     0       0      0     0      0  ...   \n",
       "992      0    1     0     0     0     0       0      0     0      0  ...   \n",
       "952      0    0     0     1     0     0       0      0     0      0  ...   \n",
       "...    ...  ...   ...   ...   ...   ...     ...    ...   ...    ...  ...   \n",
       "651      0   10     0     0     0     0       0      0     0      0  ...   \n",
       "1092     0    3     0     0     0     0       0      0     0      0  ...   \n",
       "585      0    5     0     0     1     0       0      0     0      0  ...   \n",
       "1082     0    8     0     0     0     0       0      0     0      0  ...   \n",
       "703      0    5     0     0     0     0       0      0     0      0  ...   \n",
       "\n",
       "      MGAT4A  AGAP1  SKAP1  FXYD1  NFIA  OLFM3  AMPD2  LZTS2  RGL1  BTG2  \n",
       "137        1      0      0      0     0      0      0      1     0     0  \n",
       "1582       0      0      0      0     0      0      0      0     0     0  \n",
       "1392       0      0      0      0     0      0      0      0     0     0  \n",
       "992        0      0      0      0     0      0      0      0     0     0  \n",
       "952        0      0      0      0     0      0      1      0     0     1  \n",
       "...      ...    ...    ...    ...   ...    ...    ...    ...   ...   ...  \n",
       "651        0      0      0      0     0      0      0      0     0     1  \n",
       "1092       0      0      0      0     0      0      0      1     0     1  \n",
       "585        0      3      0      0     0      0      0      1     0     0  \n",
       "1082       0      0      0      0     0      0      0      1     0     0  \n",
       "703        0      0      0      0     0      0      0      0     0     3  \n",
       "\n",
       "[1483 rows x 2000 columns]"
      ]
     },
     "execution_count": 59,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#数据转成dataFrame格式\n",
    "data_train1 = pd.concat(data_train)\n",
    "data_test1 = pd.concat(data_test)\n",
    "data_val1 = pd.concat(data_val)\n",
    "label_train1 = pd.concat(label_train)\n",
    "label_test1 = pd.concat(label_test)\n",
    "label_val1 = pd.concat(label_val)\n",
    "data_train1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>type</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>137</th>\n",
       "      <td>alpha</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1582</th>\n",
       "      <td>alpha</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1392</th>\n",
       "      <td>alpha</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>992</th>\n",
       "      <td>alpha</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>952</th>\n",
       "      <td>alpha</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>651</th>\n",
       "      <td>quiescent_stellate</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1092</th>\n",
       "      <td>quiescent_stellate</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>585</th>\n",
       "      <td>quiescent_stellate</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1082</th>\n",
       "      <td>quiescent_stellate</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>703</th>\n",
       "      <td>quiescent_stellate</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>1483 rows × 1 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                    type\n",
       "137                alpha\n",
       "1582               alpha\n",
       "1392               alpha\n",
       "992                alpha\n",
       "952                alpha\n",
       "...                  ...\n",
       "651   quiescent_stellate\n",
       "1092  quiescent_stellate\n",
       "585   quiescent_stellate\n",
       "1082  quiescent_stellate\n",
       "703   quiescent_stellate\n",
       "\n",
       "[1483 rows x 1 columns]"
      ]
     },
     "execution_count": 60,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "label_train1"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## ' save objects 将上面的处理好的数据序列化到磁盘文件datasets.dat，下次通过pkl.load 装载数据\n",
    "\n",
    "    PIK = \"{}/datasets.dat\".format(DataDir)\n",
    "    res = [\n",
    "        data_train1, data_test1, data_val1, label_train1, label_test1,\n",
    "        label_val1, lab_data2, lab_label2, types\n",
    "    ]\n",
    "\n",
    "    with open(PIK, \"wb\") as f:\n",
    "        pkl.dump(res, f)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 62,
   "metadata": {},
   "outputs": [],
   "source": [
    "#回到scGCN/utils.py#L45行def load_data(datadir,rgraph=True): 开始分析"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 61,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pickle as pkl\n",
    "import scipy.sparse\n",
    "import numpy as np\n",
    "import pandas as pd\n",
    "from scipy import sparse as sp\n",
    "import networkx as nx\n",
    "from data import *\n",
    "from collections import defaultdict\n",
    "from scipy.stats import uniform"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 63,
   "metadata": {},
   "outputs": [],
   "source": [
    "PIK = \"/Users/hufox/scGCN/scGCN/input/datasets.dat\"\n",
    "with open(PIK, \"rb\") as f:\n",
    "    objects = pkl.load(f)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 64,
   "metadata": {},
   "outputs": [],
   "source": [
    "#从磁盘装载数据\n",
    "data_train1, data_test1, data_val1, label_train1, label_test1, label_val1, lab_data2, lab_label2, types = tuple(\n",
    "        objects)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 65,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>APOE</th>\n",
       "      <th>B2M</th>\n",
       "      <th>CD53</th>\n",
       "      <th>CD74</th>\n",
       "      <th>CD93</th>\n",
       "      <th>CDH5</th>\n",
       "      <th>CORO1A</th>\n",
       "      <th>CSF1R</th>\n",
       "      <th>CTSS</th>\n",
       "      <th>EGFL7</th>\n",
       "      <th>...</th>\n",
       "      <th>MGAT4A</th>\n",
       "      <th>AGAP1</th>\n",
       "      <th>SKAP1</th>\n",
       "      <th>FXYD1</th>\n",
       "      <th>NFIA</th>\n",
       "      <th>OLFM3</th>\n",
       "      <th>AMPD2</th>\n",
       "      <th>LZTS2</th>\n",
       "      <th>RGL1</th>\n",
       "      <th>BTG2</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>137</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1582</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1392</th>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>992</th>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>952</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>651</th>\n",
       "      <td>0</td>\n",
       "      <td>10</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1092</th>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>585</th>\n",
       "      <td>0</td>\n",
       "      <td>5</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1082</th>\n",
       "      <td>0</td>\n",
       "      <td>8</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>703</th>\n",
       "      <td>0</td>\n",
       "      <td>5</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>1483 rows × 2000 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "      APOE  B2M  CD53  CD74  CD93  CDH5  CORO1A  CSF1R  CTSS  EGFL7  ...  \\\n",
       "137      0    0     0     0     0     0       0      0     0      0  ...   \n",
       "1582     0    0     0     0     0     0       0      0     0      0  ...   \n",
       "1392     0    3     0     0     0     0       0      0     0      0  ...   \n",
       "992      0    1     0     0     0     0       0      0     0      0  ...   \n",
       "952      0    0     0     1     0     0       0      0     0      0  ...   \n",
       "...    ...  ...   ...   ...   ...   ...     ...    ...   ...    ...  ...   \n",
       "651      0   10     0     0     0     0       0      0     0      0  ...   \n",
       "1092     0    3     0     0     0     0       0      0     0      0  ...   \n",
       "585      0    5     0     0     1     0       0      0     0      0  ...   \n",
       "1082     0    8     0     0     0     0       0      0     0      0  ...   \n",
       "703      0    5     0     0     0     0       0      0     0      0  ...   \n",
       "\n",
       "      MGAT4A  AGAP1  SKAP1  FXYD1  NFIA  OLFM3  AMPD2  LZTS2  RGL1  BTG2  \n",
       "137        1      0      0      0     0      0      0      1     0     0  \n",
       "1582       0      0      0      0     0      0      0      0     0     0  \n",
       "1392       0      0      0      0     0      0      0      0     0     0  \n",
       "992        0      0      0      0     0      0      0      0     0     0  \n",
       "952        0      0      0      0     0      0      1      0     0     1  \n",
       "...      ...    ...    ...    ...   ...    ...    ...    ...   ...   ...  \n",
       "651        0      0      0      0     0      0      0      0     0     1  \n",
       "1092       0      0      0      0     0      0      0      1     0     1  \n",
       "585        0      3      0      0     0      0      0      1     0     0  \n",
       "1082       0      0      0      0     0      0      0      1     0     0  \n",
       "703        0      0      0      0     0      0      0      0     0     3  \n",
       "\n",
       "[1483 rows x 2000 columns]"
      ]
     },
     "execution_count": 65,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data_train1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 66,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>APOE</th>\n",
       "      <th>B2M</th>\n",
       "      <th>CD53</th>\n",
       "      <th>CD74</th>\n",
       "      <th>CD93</th>\n",
       "      <th>CDH5</th>\n",
       "      <th>CORO1A</th>\n",
       "      <th>CSF1R</th>\n",
       "      <th>CTSS</th>\n",
       "      <th>EGFL7</th>\n",
       "      <th>...</th>\n",
       "      <th>MGAT4A</th>\n",
       "      <th>AGAP1</th>\n",
       "      <th>SKAP1</th>\n",
       "      <th>FXYD1</th>\n",
       "      <th>NFIA</th>\n",
       "      <th>OLFM3</th>\n",
       "      <th>AMPD2</th>\n",
       "      <th>LZTS2</th>\n",
       "      <th>RGL1</th>\n",
       "      <th>BTG2</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>137</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1582</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1392</th>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>992</th>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>952</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7259</th>\n",
       "      <td>0</td>\n",
       "      <td>5</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7260</th>\n",
       "      <td>0</td>\n",
       "      <td>8</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7261</th>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7262</th>\n",
       "      <td>0</td>\n",
       "      <td>6</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7263</th>\n",
       "      <td>0</td>\n",
       "      <td>25</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>8747 rows × 2000 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "      APOE  B2M  CD53  CD74  CD93  CDH5  CORO1A  CSF1R  CTSS  EGFL7  ...  \\\n",
       "137      0    0     0     0     0     0       0      0     0      0  ...   \n",
       "1582     0    0     0     0     0     0       0      0     0      0  ...   \n",
       "1392     0    3     0     0     0     0       0      0     0      0  ...   \n",
       "992      0    1     0     0     0     0       0      0     0      0  ...   \n",
       "952      0    0     0     1     0     0       0      0     0      0  ...   \n",
       "...    ...  ...   ...   ...   ...   ...     ...    ...   ...    ...  ...   \n",
       "7259     0    5     0     0     0     0       0      0     0      0  ...   \n",
       "7260     0    8     0     0     0     0       0      0     0      0  ...   \n",
       "7261     0    2     0     0     0     0       0      0     0      0  ...   \n",
       "7262     0    6     0     0     0     0       0      0     0      0  ...   \n",
       "7263     0   25     0     0     0     0       0      0     0      0  ...   \n",
       "\n",
       "      MGAT4A  AGAP1  SKAP1  FXYD1  NFIA  OLFM3  AMPD2  LZTS2  RGL1  BTG2  \n",
       "137        1      0      0      0     0      0      0      1     0     0  \n",
       "1582       0      0      0      0     0      0      0      0     0     0  \n",
       "1392       0      0      0      0     0      0      0      0     0     0  \n",
       "992        0      0      0      0     0      0      0      0     0     0  \n",
       "952        0      0      0      0     0      0      1      0     0     1  \n",
       "...      ...    ...    ...    ...   ...    ...    ...    ...   ...   ...  \n",
       "7259       0      0      0      0     0      0      1      0     1     1  \n",
       "7260       0      0      0      0     1      0      0      0     0     4  \n",
       "7261       0      0      0      0     0      0      1      0     0     0  \n",
       "7262       0      0      0      0     0      0      0      0     0     0  \n",
       "7263       0      0      0      0     0      0      0      0     0     0  \n",
       "\n",
       "[8747 rows x 2000 columns]"
      ]
     },
     "execution_count": 66,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#小鼠训练集+人的7264条数据，进行半监督训练\n",
    "train2 = pd.concat([data_train1, lab_data2])\n",
    "train2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 67,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\n",
      "RangeIndex: 7264 entries, 0 to 7263\n",
      "Columns: 2000 entries, APOE to BTG2\n",
      "dtypes: int64(2000)\n",
      "memory usage: 110.8 MB\n"
     ]
    }
   ],
   "source": [
    "lab_data2.info()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 69,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>type</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>137</th>\n",
       "      <td>alpha</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1582</th>\n",
       "      <td>alpha</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1392</th>\n",
       "      <td>alpha</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>992</th>\n",
       "      <td>alpha</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>952</th>\n",
       "      <td>alpha</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7259</th>\n",
       "      <td>beta</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7260</th>\n",
       "      <td>alpha</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7261</th>\n",
       "      <td>beta</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7262</th>\n",
       "      <td>beta</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7263</th>\n",
       "      <td>ductal</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>8747 rows × 1 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "        type\n",
       "137    alpha\n",
       "1582   alpha\n",
       "1392   alpha\n",
       "992    alpha\n",
       "952    alpha\n",
       "...      ...\n",
       "7259    beta\n",
       "7260   alpha\n",
       "7261    beta\n",
       "7262    beta\n",
       "7263  ductal\n",
       "\n",
       "[8747 rows x 1 columns]"
      ]
     },
     "execution_count": 69,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "lab_train2 = pd.concat([label_train1, lab_label2])\n",
    "lab_train2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 73,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 0,  0,  0, ...,  1,  0,  0],\n",
       "       [ 0,  0,  0, ...,  0,  0,  0],\n",
       "       [ 0,  3,  0, ...,  0,  0,  0],\n",
       "       ...,\n",
       "       [ 0,  2,  0, ...,  0,  0,  0],\n",
       "       [ 0,  6,  0, ...,  0,  0,  0],\n",
       "       [ 0, 25,  0, ...,  0,  0,  0]])"
      ]
     },
     "execution_count": 73,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#训练集、测试集、验证集都转为np.array格式\n",
    "datas_train = np.array(train2)\n",
    "datas_test = np.array(data_test1)\n",
    "datas_val = np.array(data_val1)\n",
    "datas_train"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 74,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[0, 0, 0, ..., 0, 0, 1],\n",
       "       [0, 1, 0, ..., 0, 0, 0],\n",
       "       [0, 0, 0, ..., 1, 0, 5],\n",
       "       ...,\n",
       "       [0, 9, 0, ..., 0, 0, 1],\n",
       "       [0, 5, 0, ..., 0, 0, 0],\n",
       "       [1, 2, 0, ..., 0, 0, 1]])"
      ]
     },
     "execution_count": 74,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "datas_test"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 75,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[0, 0, 0, ..., 1, 0, 0],\n",
       "       [0, 0, 0, ..., 0, 0, 1],\n",
       "       [0, 0, 0, ..., 0, 0, 4],\n",
       "       ...,\n",
       "       [0, 6, 0, ..., 2, 0, 1],\n",
       "       [0, 1, 0, ..., 0, 0, 0],\n",
       "       [0, 1, 0, ..., 0, 0, 0]])"
      ]
     },
     "execution_count": 75,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "datas_val"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 77,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Int64Index([ 137, 1582, 1392,  992,  952,  880, 1699, 1037, 1339, 1635,\n",
       "            ...\n",
       "            1807,  724, 1401,  554, 1764,  651, 1092,  585, 1082,  703],\n",
       "           dtype='int64', length=1483)"
      ]
     },
     "execution_count": 77,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "label_train1.index"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 83,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "RangeIndex(start=-1, stop=-7265, step=-1)"
      ]
     },
     "execution_count": 83,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "lab_label2.index* (-1)-1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 87,
   "metadata": {},
   "outputs": [],
   "source": [
    "#索引连接，小鼠的训练集索引+人的索引（负数）+小鼠验证集索引+小鼠测试集索引\n",
    "index_guide = np.concatenate(\n",
    "        (label_train1.index, lab_label2.index * (-1) - 1, label_val1.index,\n",
    "         label_test1.index))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 88,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([ 137, 1582, 1392, ...,  108,  480,  382])"
      ]
     },
     "execution_count": 88,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "index_guide"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 91,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "-1"
      ]
     },
     "execution_count": 91,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#参加results结果文件中的scGCN_index_guide.csv 文件,从1483开始为-1索引\n",
    "index_guide[1483]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 92,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>type</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>137</th>\n",
       "      <td>alpha</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1582</th>\n",
       "      <td>alpha</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1392</th>\n",
       "      <td>alpha</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>992</th>\n",
       "      <td>alpha</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>952</th>\n",
       "      <td>alpha</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7259</th>\n",
       "      <td>beta</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7260</th>\n",
       "      <td>alpha</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7261</th>\n",
       "      <td>beta</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7262</th>\n",
       "      <td>beta</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7263</th>\n",
       "      <td>ductal</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>8747 rows × 1 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "        type\n",
       "137    alpha\n",
       "1582   alpha\n",
       "1392   alpha\n",
       "992    alpha\n",
       "952    alpha\n",
       "...      ...\n",
       "7259    beta\n",
       "7260   alpha\n",
       "7261    beta\n",
       "7262    beta\n",
       "7263  ductal\n",
       "\n",
       "[8747 rows x 1 columns]"
      ]
     },
     "execution_count": 92,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "lab_train2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 93,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([['alpha'],\n",
       "       ['alpha'],\n",
       "       ['alpha'],\n",
       "       ...,\n",
       "       ['beta'],\n",
       "       ['beta'],\n",
       "       ['ductal']], dtype=object)"
      ]
     },
     "execution_count": 93,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "labels_train = np.array(lab_train2)\n",
    "labels_train"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 95,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array(['alpha', 'alpha', 'alpha', ..., 'beta', 'beta', 'ductal'],\n",
       "      dtype=object)"
      ]
     },
     "execution_count": 95,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#将dataFrame格式的标签转为np.array 格式，并且展平\n",
    "labels_train = np.array(lab_train2).flatten()\n",
    "labels_test = np.array(label_test1).flatten()\n",
    "labels_val = np.array(label_val1).flatten()\n",
    "labels_train"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 96,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 0,  0,  0, ...,  1,  0,  0],\n",
       "       [ 0,  0,  0, ...,  0,  0,  0],\n",
       "       [ 0,  3,  0, ...,  0,  0,  0],\n",
       "       ...,\n",
       "       [ 0,  2,  0, ...,  0,  0,  0],\n",
       "       [ 0,  6,  0, ...,  0,  0,  0],\n",
       "       [ 0, 25,  0, ...,  0,  0,  0]])"
      ]
     },
     "execution_count": 96,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "datas_train"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 97,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "<ipython-input-97-32c3792149bf>:3: DeprecationWarning: Numeric-style type codes are deprecated and will result in an error in the future.\n",
      "  datas_tr = scipy.sparse.csr_matrix(datas_train.astype('Float64'))\n"
     ]
    }
   ],
   "source": [
    "#将数据转为csr矩阵\n",
    " #' convert pandas data frame to csr_matrix format\n",
    "datas_tr = scipy.sparse.csr_matrix(datas_train.astype('Float64'))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 100,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<8747x2000 sparse matrix of type '<class 'numpy.float64'>'\n",
       "\twith 3382598 stored elements in Compressed Sparse Row format>"
      ]
     },
     "execution_count": 100,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "datas_tr"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 101,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([ 3.,  2., 25., ...,  1.,  1.,  1.])"
      ]
     },
     "execution_count": 101,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "datas_tr.data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 102,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "<ipython-input-102-25b2ed881780>:1: DeprecationWarning: Numeric-style type codes are deprecated and will result in an error in the future.\n",
      "  datas_va = scipy.sparse.csr_matrix(datas_val.astype('Float64'))\n",
      "<ipython-input-102-25b2ed881780>:2: DeprecationWarning: Numeric-style type codes are deprecated and will result in an error in the future.\n",
      "  datas_te = scipy.sparse.csr_matrix(datas_test.astype('Float64'))\n"
     ]
    }
   ],
   "source": [
    "datas_va = scipy.sparse.csr_matrix(datas_val.astype('Float64'))\n",
    "datas_te = scipy.sparse.csr_matrix(datas_test.astype('Float64'))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 103,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([ 6., 20.,  6., ...,  1.,  1.,  3.])"
      ]
     },
     "execution_count": 103,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "datas_va.data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 105,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([ 7., 29.,  1., ...,  5.,  1.,  1.])"
      ]
     },
     "execution_count": 105,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "datas_te.data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 108,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([    0,   434,   744,  1143,  1593,  1952,  2315,  2789,  3102,\n",
       "        3345,  3574,  4005,  4305,  4535,  4961,  5394,  5873,  6284,\n",
       "        6533,  6756,  7216,  7777,  8149,  8641,  9080,  9369,  9973,\n",
       "       10496, 10774, 11182, 11673, 12102, 12381, 12714, 13031, 13460,\n",
       "       13944, 14271, 14767, 15009, 15454, 15652, 16114, 16470, 16942,\n",
       "       17213, 17536, 18000, 18283, 18570, 19011, 19405, 19704, 19955,\n",
       "       20270, 20473, 20820, 21137, 21556, 21888, 22073, 22282, 22495,\n",
       "       22821, 22994, 23234, 23478, 23737, 23940, 24233, 24680, 24942,\n",
       "       25462, 25699, 26011, 26331, 26734, 27299, 27608, 28041, 28418,\n",
       "       28642, 29237, 29740, 30260, 30688, 31265, 31762, 32318, 32558,\n",
       "       32848, 33260, 33545, 34067, 34656, 34882, 35462, 35878, 36175,\n",
       "       36532, 36840, 37264, 37532, 37783, 38004, 38240, 38437, 38887,\n",
       "       39134, 39536, 39765, 40002, 40501, 40750, 40966, 41370, 41675,\n",
       "       41937, 42433, 42947, 43134, 43683, 43870, 44456, 45006, 45226,\n",
       "       45652, 46168, 46703, 47006, 47558, 47930, 48404, 48980, 49298,\n",
       "       49894, 50130, 50646, 51148, 51783, 52385, 53041, 53661, 53912,\n",
       "       54297, 54893, 55385, 55826, 56578, 56979, 57221, 57597, 58172,\n",
       "       58729, 59294, 59567, 60092, 60584, 61165, 61506, 61789, 62304,\n",
       "       62885, 63550, 63849, 64252, 64825, 65200, 65736, 66368, 66783,\n",
       "       67260, 67899, 68397, 69009, 69310, 69738, 69981, 70438, 70709,\n",
       "       71045, 71491, 72030, 72358, 72749, 73193, 73722, 74176, 74620],\n",
       "      dtype=int32)"
      ]
     },
     "execution_count": 108,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#每行第一个非0元索引和最后一个非0元索引\n",
    "datas_te.indptr"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 107,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([  11,   12,   23, ..., 1993, 1994, 1999], dtype=int32)"
      ]
     },
     "execution_count": 107,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#每个非0元对应的索引\n",
    "datas_te.indices"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 111,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1483"
      ]
     },
     "execution_count": 111,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#训练集中标记样本的数量\n",
    "#the number of labeled samples in training set\n",
    "M = len(data_train1)\n",
    "M"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 113,
   "metadata": {},
   "outputs": [],
   "source": [
    "#' 4) get the feature object by combining training, test, valiation sets\n",
    "#sp.vstack()垂直堆叠稀疏矩阵（按行）\n",
    "#csr_matrix.tolil() Convert this matrix to List of Lists format.将矩阵转换为list，提高运行效率\n",
    "features = sp.vstack((sp.vstack((datas_tr, datas_va)), datas_te)).tolil()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 119,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([list([3.0, 2.0, 25.0, 1.0, 52.0, 31.0, 1.0, 1.0, 14.0, 1.0, 3.0, 5.0, 14.0, 1.0, 1.0, 1.0, 3.0, 3.0, 1.0, 11.0, 2.0, 4.0, 1.0, 2.0, 1.0, 1.0, 1.0, 11.0, 2.0, 1.0, 1.0, 1.0, 3.0, 1.0, 3.0, 1.0, 1.0, 3.0, 3.0, 2.0, 1.0, 1.0, 2.0, 1.0, 1.0, 1.0, 3.0, 1.0, 1.0, 1.0, 1.0, 1.0, 3.0, 2.0, 2.0, 1.0, 1.0, 3.0, 1.0, 1.0, 2.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 2.0, 2.0, 1.0, 3.0, 1.0, 1.0, 1.0, 1.0, 1.0, 2.0, 1.0, 1.0, 4.0, 2.0, 4.0, 1.0, 1.0, 2.0, 1.0, 1.0, 1.0, 2.0, 2.0, 4.0, 1.0, 1.0, 1.0, 1.0, 1.0, 4.0, 2.0, 4.0, 1.0, 2.0, 1.0, 2.0, 1.0, 1.0, 3.0, 1.0, 1.0, 2.0, 1.0, 4.0, 1.0, 1.0, 2.0, 3.0, 1.0, 1.0, 2.0, 2.0, 6.0, 2.0, 1.0, 5.0, 1.0, 1.0, 1.0, 2.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 2.0, 2.0, 1.0, 1.0, 1.0, 1.0, 3.0, 1.0, 1.0, 1.0, 1.0, 1.0, 2.0, 1.0, 1.0, 3.0, 1.0, 1.0, 1.0, 3.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 6.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 3.0, 2.0, 1.0, 1.0, 1.0, 2.0, 3.0, 1.0, 1.0, 3.0, 3.0, 1.0, 1.0, 3.0, 2.0, 1.0, 1.0, 1.0, 1.0, 2.0, 3.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 2.0, 8.0, 1.0, 1.0, 1.0, 2.0, 6.0, 1.0, 2.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 2.0, 1.0, 1.0, 2.0, 1.0, 2.0, 2.0, 2.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 2.0, 2.0, 1.0, 1.0, 1.0, 1.0, 1.0, 2.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 2.0, 2.0, 2.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 2.0, 2.0, 2.0, 1.0, 2.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 2.0, 3.0, 1.0, 1.0, 1.0, 1.0, 2.0, 1.0, 1.0, 1.0, 2.0, 2.0, 1.0, 1.0, 2.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 2.0, 2.0, 1.0, 1.0, 1.0, 1.0, 2.0, 3.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 3.0, 1.0, 2.0, 1.0, 1.0, 1.0, 1.0, 1.0, 4.0, 2.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 2.0, 1.0, 2.0, 2.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 3.0, 1.0, 2.0, 1.0, 1.0, 1.0, 1.0]),\n",
       "       list([1.0, 42.0, 19.0, 2.0, 3.0, 44.0, 6.0, 40.0, 3.0, 14.0, 2.0, 4.0, 32.0, 1.0, 4.0, 9.0, 29.0, 1.0, 7.0, 54.0, 1.0, 4.0, 1.0, 3.0, 10.0, 1.0, 2.0, 12.0, 1.0, 103.0, 4.0, 2.0, 2.0, 2.0, 23.0, 9.0, 12.0, 16.0, 1.0, 1.0, 1.0, 1.0, 4.0, 2.0, 1.0, 9.0, 2.0, 7.0, 2.0, 1.0, 2.0, 2.0, 2.0, 3.0, 2.0, 5.0, 1.0, 2.0, 3.0, 1.0, 6.0, 2.0, 1.0, 2.0, 1.0, 16.0, 1.0, 4.0, 1.0, 6.0, 10.0, 2.0, 1.0, 6.0, 9.0, 1.0, 2.0, 2.0, 7.0, 3.0, 5.0, 7.0, 2.0, 1.0, 3.0, 11.0, 1.0, 3.0, 1.0, 2.0, 4.0, 1.0, 7.0, 2.0, 5.0, 5.0, 1.0, 1.0, 3.0, 5.0, 1.0, 1.0, 5.0, 6.0, 4.0, 6.0, 6.0, 20.0, 1.0, 11.0, 2.0, 9.0, 5.0, 2.0, 3.0, 1.0, 1.0, 7.0, 7.0, 1.0, 1.0, 2.0, 1.0, 2.0, 2.0, 1.0, 1.0, 5.0, 2.0, 1.0, 5.0, 7.0, 1.0, 2.0, 4.0, 3.0, 1.0, 2.0, 2.0, 3.0, 1.0, 7.0, 4.0, 8.0, 2.0, 1.0, 11.0, 8.0, 3.0, 1.0, 2.0, 1.0, 1.0, 7.0, 9.0, 5.0, 2.0, 1.0, 1.0, 12.0, 5.0, 1.0, 1.0, 10.0, 1.0, 5.0, 2.0, 4.0, 1.0, 7.0, 1.0, 5.0, 3.0, 2.0, 4.0, 1.0, 2.0, 1.0, 2.0, 8.0, 2.0, 1.0, 7.0, 1.0, 1.0, 1.0, 4.0, 1.0, 4.0, 3.0, 6.0, 4.0, 2.0, 5.0, 2.0, 3.0, 3.0, 2.0, 7.0, 1.0, 2.0, 1.0, 16.0, 3.0, 1.0, 2.0, 32.0, 1.0, 2.0, 3.0, 1.0, 1.0, 6.0, 6.0, 10.0, 1.0, 2.0, 1.0, 2.0, 1.0, 1.0, 4.0, 7.0, 2.0, 1.0, 1.0, 1.0, 1.0, 6.0, 1.0, 7.0, 1.0, 1.0, 2.0, 2.0, 2.0, 1.0, 1.0, 11.0, 3.0, 1.0, 2.0, 2.0, 1.0, 1.0, 1.0, 6.0, 9.0, 8.0, 5.0, 3.0, 1.0, 6.0, 3.0, 5.0, 2.0, 2.0, 6.0, 1.0, 4.0, 1.0, 1.0, 6.0, 1.0, 4.0, 1.0, 2.0, 1.0, 2.0, 1.0, 1.0, 7.0, 2.0, 1.0, 1.0, 1.0, 2.0, 4.0, 1.0, 1.0, 2.0, 1.0, 1.0, 1.0, 3.0, 5.0, 2.0, 1.0, 1.0, 14.0, 3.0, 1.0, 4.0, 1.0, 1.0, 2.0, 2.0, 1.0, 3.0, 5.0, 3.0, 4.0, 2.0, 3.0, 3.0, 6.0, 1.0, 1.0, 5.0, 1.0, 1.0, 1.0, 1.0, 1.0, 2.0, 6.0, 4.0, 1.0, 1.0, 1.0, 2.0, 4.0, 1.0, 2.0, 2.0, 2.0, 2.0, 1.0, 1.0, 4.0, 2.0, 2.0, 1.0, 3.0, 1.0, 9.0, 1.0, 1.0, 2.0, 1.0, 8.0, 1.0, 3.0, 1.0, 1.0, 1.0, 1.0, 2.0, 1.0, 1.0, 2.0, 2.0, 15.0, 2.0, 1.0, 2.0, 2.0, 1.0, 1.0, 12.0, 29.0, 1.0, 4.0, 2.0, 2.0, 1.0, 2.0, 4.0, 3.0, 2.0, 1.0, 3.0, 4.0, 2.0, 10.0, 1.0, 3.0, 1.0, 7.0, 2.0, 2.0, 1.0, 1.0, 3.0, 3.0, 29.0, 3.0, 1.0, 1.0, 3.0, 1.0, 1.0, 1.0, 1.0]),\n",
       "       list([3.0, 1.0, 6.0, 4.0, 1.0, 3.0, 149.0, 3.0, 13.0, 3.0, 11.0, 2.0, 2.0, 2.0, 4.0, 4.0, 1.0, 20.0, 1.0, 3.0, 7.0, 13.0, 4.0, 1.0, 3.0, 1.0, 4.0, 1.0, 2.0, 1.0, 19.0, 4.0, 2.0, 1.0, 1.0, 1.0, 8.0, 3.0, 9.0, 10.0, 1.0, 2.0, 3.0, 1.0, 2.0, 1.0, 8.0, 2.0, 3.0, 7.0, 1.0, 4.0, 3.0, 1.0, 1.0, 2.0, 2.0, 1.0, 1.0, 1.0, 1.0, 2.0, 1.0, 3.0, 1.0, 1.0, 1.0, 6.0, 2.0, 11.0, 1.0, 4.0, 2.0, 1.0, 2.0, 2.0, 2.0, 1.0, 3.0, 1.0, 2.0, 7.0, 1.0, 1.0, 2.0, 4.0, 7.0, 3.0, 10.0, 9.0, 1.0, 1.0, 1.0, 8.0, 1.0, 5.0, 5.0, 1.0, 3.0, 1.0, 1.0, 1.0, 9.0, 1.0, 1.0, 2.0, 9.0, 1.0, 9.0, 1.0, 2.0, 1.0, 1.0, 2.0, 1.0, 14.0, 2.0, 1.0, 1.0, 6.0, 1.0, 2.0, 1.0, 2.0, 1.0, 2.0, 1.0, 2.0, 1.0, 2.0, 1.0, 1.0, 1.0, 4.0, 4.0, 4.0, 3.0, 1.0, 11.0, 7.0, 2.0, 6.0, 1.0, 1.0, 1.0, 1.0, 1.0, 2.0, 2.0, 2.0, 4.0, 1.0, 1.0, 16.0, 3.0, 6.0, 14.0, 3.0, 1.0, 4.0, 9.0, 7.0, 1.0, 1.0, 10.0, 6.0, 4.0, 1.0, 18.0, 2.0, 2.0, 3.0, 1.0, 2.0, 3.0, 1.0, 7.0, 2.0, 6.0, 11.0, 1.0, 1.0, 9.0, 5.0, 5.0, 1.0, 2.0, 1.0, 1.0, 1.0, 5.0, 5.0, 5.0, 1.0, 1.0, 11.0, 1.0, 30.0, 1.0, 4.0, 1.0, 7.0, 3.0, 1.0, 4.0, 2.0, 1.0, 2.0, 2.0, 1.0, 6.0, 2.0, 3.0, 1.0, 2.0, 1.0, 1.0, 1.0, 1.0, 4.0, 2.0, 1.0, 1.0, 3.0, 2.0, 1.0, 7.0, 2.0, 1.0, 1.0, 4.0, 3.0, 1.0, 2.0, 1.0, 9.0, 2.0, 1.0, 4.0, 2.0, 1.0, 6.0, 3.0, 3.0, 3.0, 1.0, 3.0, 3.0, 1.0, 1.0, 1.0, 1.0, 3.0, 2.0, 3.0, 1.0, 1.0, 2.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 4.0, 7.0, 1.0, 3.0, 3.0, 1.0, 3.0, 5.0, 1.0, 1.0, 1.0, 1.0, 2.0, 2.0, 2.0, 1.0, 1.0, 1.0, 2.0, 1.0, 1.0, 6.0, 1.0, 2.0, 1.0, 5.0, 1.0, 1.0, 2.0, 3.0, 1.0, 1.0, 4.0, 1.0, 1.0, 1.0, 2.0, 25.0, 1.0, 1.0, 4.0, 1.0, 1.0, 1.0, 2.0, 1.0, 4.0, 1.0, 2.0, 1.0, 1.0, 5.0, 2.0, 1.0, 12.0, 1.0, 4.0, 3.0, 3.0, 1.0, 3.0, 2.0, 1.0]),\n",
       "       ...,\n",
       "       list([9.0, 1.0, 2.0, 8.0, 6.0, 21.0, 2.0, 3.0, 24.0, 11.0, 1.0, 1.0, 4.0, 19.0, 29.0, 8.0, 4.0, 3.0, 8.0, 10.0, 18.0, 18.0, 14.0, 1.0, 1.0, 2.0, 3.0, 1.0, 1.0, 3.0, 1.0, 4.0, 9.0, 2.0, 1.0, 1.0, 4.0, 5.0, 9.0, 93.0, 1.0, 2.0, 4.0, 1.0, 21.0, 1.0, 2.0, 1.0, 3.0, 7.0, 4.0, 1.0, 2.0, 4.0, 1.0, 11.0, 4.0, 8.0, 1.0, 2.0, 36.0, 9.0, 3.0, 9.0, 1.0, 3.0, 1.0, 5.0, 4.0, 1.0, 3.0, 54.0, 2.0, 2.0, 30.0, 1.0, 2.0, 28.0, 4.0, 2.0, 1.0, 1.0, 2.0, 1.0, 2.0, 2.0, 2.0, 1.0, 3.0, 11.0, 1.0, 16.0, 10.0, 6.0, 2.0, 5.0, 5.0, 4.0, 1.0, 1.0, 2.0, 2.0, 5.0, 1.0, 1.0, 1.0, 8.0, 2.0, 2.0, 1.0, 43.0, 2.0, 10.0, 1.0, 2.0, 1.0, 1.0, 1.0, 2.0, 9.0, 2.0, 8.0, 2.0, 3.0, 7.0, 3.0, 1.0, 3.0, 11.0, 9.0, 2.0, 1.0, 3.0, 4.0, 3.0, 1.0, 1.0, 9.0, 1.0, 1.0, 3.0, 1.0, 3.0, 1.0, 1.0, 3.0, 12.0, 1.0, 1.0, 7.0, 3.0, 341.0, 1.0, 3.0, 1.0, 1.0, 3.0, 1.0, 3.0, 4.0, 1.0, 13.0, 9.0, 1.0, 2.0, 5.0, 4.0, 3.0, 4.0, 6.0, 1.0, 2.0, 1.0, 1.0, 15.0, 1.0, 2.0, 1.0, 2.0, 15.0, 6.0, 2.0, 4.0, 5.0, 1.0, 10.0, 6.0, 4.0, 1.0, 2.0, 10.0, 4.0, 2.0, 1.0, 1.0, 1.0, 5.0, 1.0, 1.0, 1.0, 14.0, 3.0, 3.0, 3.0, 2.0, 6.0, 1.0, 1.0, 5.0, 5.0, 5.0, 2.0, 1.0, 17.0, 2.0, 1.0, 1.0, 3.0, 4.0, 4.0, 6.0, 3.0, 2.0, 8.0, 4.0, 7.0, 1.0, 7.0, 10.0, 2.0, 2.0, 6.0, 3.0, 1.0, 1.0, 2.0, 6.0, 3.0, 1.0, 2.0, 1.0, 5.0, 1.0, 1.0, 2.0, 5.0, 2.0, 4.0, 1.0, 3.0, 13.0, 1.0, 1.0, 3.0, 10.0, 6.0, 1.0, 2.0, 4.0, 4.0, 3.0, 4.0, 2.0, 3.0, 1.0, 1.0, 5.0, 2.0, 1.0, 4.0, 11.0, 2.0, 6.0, 10.0, 8.0, 1.0, 2.0, 4.0, 2.0, 2.0, 2.0, 7.0, 4.0, 2.0, 1.0, 12.0, 1.0, 11.0, 1.0, 1.0, 8.0, 9.0, 18.0, 1.0, 8.0, 1.0, 1.0, 1.0, 1.0, 4.0, 2.0, 3.0, 9.0, 4.0, 2.0, 5.0, 3.0, 2.0, 2.0, 3.0, 1.0, 1.0, 3.0, 2.0, 1.0, 1.0, 1.0, 3.0, 6.0, 3.0, 10.0, 1.0, 13.0, 2.0, 3.0, 3.0, 1.0, 2.0, 1.0, 1.0, 2.0, 4.0, 2.0, 1.0, 3.0, 1.0, 2.0, 7.0, 2.0, 1.0, 1.0, 2.0, 12.0, 2.0, 2.0, 20.0, 1.0, 1.0, 1.0, 1.0, 4.0, 3.0, 3.0, 3.0, 1.0, 3.0, 2.0, 7.0, 1.0, 2.0, 1.0, 1.0, 4.0, 5.0, 4.0, 1.0, 1.0, 3.0, 1.0, 1.0, 5.0, 1.0, 3.0, 2.0, 1.0, 4.0, 2.0, 1.0, 2.0, 6.0, 13.0, 2.0, 2.0, 3.0, 6.0, 3.0, 4.0, 5.0, 1.0, 1.0, 1.0, 1.0, 2.0, 13.0, 1.0, 1.0, 2.0, 2.0, 2.0, 1.0, 1.0, 1.0, 3.0, 1.0, 3.0, 1.0, 1.0, 1.0, 5.0, 2.0, 2.0, 2.0, 1.0, 4.0, 2.0, 2.0, 1.0, 2.0, 1.0, 2.0, 2.0, 2.0, 1.0, 1.0, 1.0, 1.0, 1.0, 4.0, 2.0, 2.0, 3.0, 2.0, 3.0, 2.0, 1.0, 4.0, 2.0, 1.0, 3.0, 4.0, 2.0, 1.0, 7.0, 1.0, 1.0, 1.0, 1.0, 1.0, 4.0, 1.0, 1.0, 1.0, 5.0, 5.0, 4.0, 2.0, 1.0, 2.0, 1.0, 2.0, 3.0, 2.0, 2.0, 1.0, 1.0, 1.0, 2.0, 2.0, 18.0, 2.0, 2.0, 5.0, 4.0, 1.0, 3.0, 1.0, 3.0, 1.0, 3.0, 1.0, 1.0, 4.0, 2.0, 3.0, 2.0, 2.0, 2.0, 1.0, 6.0, 1.0, 1.0, 2.0, 4.0, 1.0, 2.0, 25.0, 1.0, 4.0, 1.0, 1.0, 1.0, 1.0, 6.0, 3.0, 2.0, 2.0, 1.0, 1.0, 5.0, 1.0, 1.0, 3.0, 1.0, 2.0, 1.0, 2.0, 3.0, 1.0, 4.0, 11.0, 2.0, 5.0, 1.0, 1.0, 2.0, 3.0, 1.0, 2.0, 1.0]),\n",
       "       list([5.0, 5.0, 5.0, 21.0, 4.0, 1.0, 9.0, 8.0, 36.0, 3.0, 1.0, 1.0, 6.0, 23.0, 3.0, 1.0, 6.0, 6.0, 4.0, 2.0, 1.0, 5.0, 21.0, 3.0, 17.0, 34.0, 1.0, 2.0, 14.0, 1.0, 2.0, 4.0, 2.0, 1.0, 5.0, 5.0, 1.0, 16.0, 2.0, 2.0, 1.0, 5.0, 2.0, 16.0, 2.0, 1.0, 19.0, 1.0, 1.0, 2.0, 2.0, 3.0, 3.0, 4.0, 3.0, 4.0, 3.0, 1.0, 1.0, 26.0, 4.0, 7.0, 1.0, 1.0, 5.0, 3.0, 2.0, 4.0, 5.0, 1.0, 1.0, 4.0, 3.0, 6.0, 1.0, 2.0, 40.0, 11.0, 2.0, 2.0, 7.0, 1.0, 5.0, 2.0, 1.0, 1.0, 11.0, 1.0, 4.0, 1.0, 1.0, 4.0, 6.0, 6.0, 5.0, 1.0, 7.0, 1.0, 1.0, 1.0, 2.0, 7.0, 2.0, 1.0, 2.0, 2.0, 3.0, 1.0, 1.0, 3.0, 4.0, 2.0, 133.0, 9.0, 1.0, 1.0, 5.0, 1.0, 1.0, 6.0, 3.0, 1.0, 8.0, 1.0, 5.0, 5.0, 2.0, 1.0, 2.0, 1.0, 1.0, 3.0, 1.0, 16.0, 2.0, 8.0, 3.0, 2.0, 3.0, 5.0, 4.0, 1.0, 2.0, 1.0, 2.0, 2.0, 2.0, 2.0, 6.0, 4.0, 3.0, 7.0, 3.0, 13.0, 6.0, 2.0, 3.0, 3.0, 5.0, 1.0, 1.0, 5.0, 2.0, 3.0, 1.0, 3.0, 1.0, 4.0, 2.0, 1.0, 3.0, 5.0, 3.0, 1.0, 1.0, 1.0, 4.0, 1.0, 8.0, 1.0, 1.0, 1.0, 21.0, 1.0, 1.0, 3.0, 2.0, 3.0, 3.0, 2.0, 1.0, 2.0, 2.0, 1.0, 2.0, 2.0, 1.0, 1.0, 3.0, 3.0, 1.0, 1.0, 3.0, 3.0, 6.0, 1.0, 4.0, 1.0, 2.0, 4.0, 4.0, 5.0, 2.0, 10.0, 2.0, 3.0, 4.0, 1.0, 1.0, 1.0, 2.0, 4.0, 4.0, 4.0, 1.0, 7.0, 2.0, 2.0, 1.0, 4.0, 1.0, 1.0, 1.0, 1.0, 1.0, 6.0, 1.0, 9.0, 2.0, 6.0, 1.0, 2.0, 1.0, 1.0, 6.0, 3.0, 8.0, 6.0, 3.0, 5.0, 6.0, 1.0, 3.0, 1.0, 3.0, 6.0, 2.0, 2.0, 3.0, 1.0, 5.0, 1.0, 1.0, 12.0, 4.0, 1.0, 1.0, 2.0, 4.0, 2.0, 2.0, 1.0, 5.0, 3.0, 14.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 18.0, 4.0, 1.0, 1.0, 2.0, 9.0, 2.0, 1.0, 2.0, 1.0, 2.0, 2.0, 2.0, 3.0, 2.0, 13.0, 1.0, 3.0, 1.0, 1.0, 1.0, 1.0, 2.0, 1.0, 2.0, 2.0, 2.0, 2.0, 4.0, 1.0, 1.0, 2.0, 5.0, 1.0, 2.0, 2.0, 1.0, 1.0, 1.0, 1.0, 1.0, 2.0, 1.0, 2.0, 1.0, 3.0, 1.0, 1.0, 4.0, 1.0, 1.0, 2.0, 1.0, 1.0, 2.0, 2.0, 2.0, 2.0, 2.0, 1.0, 1.0, 3.0, 8.0, 3.0, 6.0, 15.0, 5.0, 1.0, 2.0, 1.0, 1.0, 1.0, 2.0, 1.0, 2.0, 1.0, 1.0, 2.0, 2.0, 1.0, 3.0, 2.0, 1.0, 3.0, 2.0, 1.0, 1.0, 3.0, 3.0, 4.0, 3.0, 1.0, 3.0, 3.0, 1.0, 1.0, 1.0, 1.0, 1.0, 6.0, 2.0, 1.0, 6.0, 1.0, 1.0, 1.0, 1.0, 2.0, 1.0, 2.0, 1.0, 1.0, 4.0, 7.0, 2.0, 1.0, 1.0, 3.0, 2.0, 4.0, 3.0, 1.0, 4.0, 6.0, 1.0, 2.0, 2.0, 4.0, 1.0, 3.0, 2.0, 2.0, 3.0, 5.0, 1.0, 3.0, 1.0, 1.0, 1.0, 1.0, 7.0, 3.0, 6.0, 8.0, 3.0, 6.0, 1.0, 5.0, 2.0, 1.0, 2.0, 2.0, 1.0, 1.0, 6.0, 3.0, 4.0, 1.0, 1.0, 2.0, 1.0, 1.0, 5.0, 1.0, 1.0, 4.0, 13.0, 7.0, 2.0, 1.0, 1.0]),\n",
       "       list([1.0, 2.0, 9.0, 5.0, 4.0, 5.0, 3.0, 3.0, 51.0, 3.0, 1.0, 4.0, 8.0, 1.0, 1.0, 1.0, 11.0, 7.0, 25.0, 4.0, 4.0, 11.0, 19.0, 5.0, 1.0, 3.0, 13.0, 8.0, 6.0, 5.0, 3.0, 1.0, 3.0, 21.0, 8.0, 2.0, 3.0, 3.0, 2.0, 3.0, 20.0, 1.0, 7.0, 46.0, 2.0, 7.0, 1.0, 3.0, 2.0, 1.0, 22.0, 4.0, 1.0, 3.0, 1.0, 1.0, 1.0, 1.0, 6.0, 5.0, 3.0, 35.0, 2.0, 1.0, 1.0, 1.0, 2.0, 41.0, 3.0, 1.0, 9.0, 4.0, 6.0, 1.0, 4.0, 2.0, 4.0, 2.0, 1.0, 2.0, 29.0, 1.0, 1.0, 7.0, 4.0, 1.0, 4.0, 1.0, 3.0, 2.0, 2.0, 2.0, 5.0, 1.0, 2.0, 4.0, 1.0, 1.0, 1.0, 2.0, 1.0, 1.0, 1.0, 3.0, 3.0, 1.0, 1.0, 1.0, 1.0, 4.0, 1.0, 437.0, 7.0, 1.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 3.0, 7.0, 6.0, 3.0, 2.0, 8.0, 6.0, 3.0, 1.0, 8.0, 3.0, 3.0, 1.0, 10.0, 1.0, 4.0, 1.0, 2.0, 6.0, 2.0, 4.0, 2.0, 1.0, 11.0, 2.0, 1.0, 1.0, 6.0, 1.0, 5.0, 4.0, 1.0, 9.0, 2.0, 1.0, 1.0, 3.0, 6.0, 1.0, 2.0, 3.0, 1.0, 6.0, 1.0, 3.0, 2.0, 1.0, 1.0, 3.0, 4.0, 5.0, 7.0, 1.0, 5.0, 1.0, 1.0, 2.0, 1.0, 4.0, 2.0, 1.0, 1.0, 1.0, 3.0, 1.0, 8.0, 1.0, 2.0, 7.0, 1.0, 1.0, 1.0, 3.0, 4.0, 2.0, 1.0, 1.0, 3.0, 1.0, 2.0, 8.0, 1.0, 4.0, 4.0, 3.0, 2.0, 3.0, 1.0, 4.0, 9.0, 3.0, 2.0, 2.0, 5.0, 2.0, 11.0, 6.0, 2.0, 1.0, 7.0, 1.0, 5.0, 1.0, 2.0, 4.0, 1.0, 2.0, 6.0, 7.0, 6.0, 1.0, 1.0, 1.0, 2.0, 1.0, 8.0, 3.0, 3.0, 7.0, 3.0, 1.0, 2.0, 2.0, 2.0, 3.0, 11.0, 5.0, 5.0, 1.0, 5.0, 1.0, 2.0, 1.0, 2.0, 1.0, 1.0, 1.0, 1.0, 7.0, 1.0, 1.0, 7.0, 2.0, 2.0, 1.0, 2.0, 1.0, 1.0, 4.0, 1.0, 24.0, 1.0, 1.0, 1.0, 2.0, 1.0, 1.0, 1.0, 4.0, 1.0, 6.0, 1.0, 4.0, 3.0, 1.0, 2.0, 6.0, 9.0, 2.0, 1.0, 4.0, 2.0, 2.0, 4.0, 5.0, 1.0, 1.0, 2.0, 1.0, 2.0, 2.0, 1.0, 2.0, 1.0, 4.0, 6.0, 3.0, 2.0, 1.0, 7.0, 3.0, 14.0, 1.0, 1.0, 5.0, 1.0, 7.0, 2.0, 1.0, 1.0, 1.0, 5.0, 1.0, 1.0, 2.0, 1.0, 3.0, 1.0, 5.0, 1.0, 1.0, 5.0, 4.0, 2.0, 1.0, 1.0, 3.0, 1.0, 1.0, 2.0, 2.0, 1.0, 11.0, 1.0, 1.0, 1.0, 3.0, 1.0, 1.0, 1.0, 1.0, 2.0, 5.0, 1.0, 2.0, 2.0, 1.0, 2.0, 1.0, 1.0, 1.0, 1.0, 1.0, 5.0, 1.0, 4.0, 5.0, 2.0, 1.0, 1.0, 1.0, 2.0, 6.0, 1.0, 1.0, 1.0, 2.0, 1.0, 2.0, 8.0, 4.0, 3.0, 1.0, 2.0, 1.0, 3.0, 2.0, 3.0, 2.0, 1.0, 2.0, 1.0, 1.0, 1.0, 2.0, 5.0, 1.0, 1.0, 1.0, 1.0, 2.0, 1.0, 5.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 2.0, 1.0, 11.0, 1.0, 1.0, 4.0, 1.0, 2.0, 3.0, 1.0, 1.0, 1.0, 6.0, 1.0, 1.0, 7.0, 1.0, 6.0, 1.0, 1.0, 2.0, 1.0, 1.0, 3.0, 2.0, 1.0, 10.0, 4.0, 6.0, 2.0, 2.0, 1.0, 5.0, 1.0, 1.0])],\n",
       "      dtype=object)"
      ]
     },
     "execution_count": 119,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "features.data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 120,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "matrix([[ 668.],\n",
       "        [1694.],\n",
       "        [1180.],\n",
       "        ...,\n",
       "        [2468.],\n",
       "        [1684.],\n",
       "        [1983.]])"
      ]
     },
     "execution_count": 120,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "features.sum(1)#对给定轴上的矩阵求和"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 121,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 668.],\n",
       "       [1694.],\n",
       "       [1180.],\n",
       "       ...,\n",
       "       [2468.],\n",
       "       [1684.],\n",
       "       [1983.]])"
      ]
     },
     "execution_count": 121,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.array(features.sum(1))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 122,
   "metadata": {},
   "outputs": [],
   "source": [
    "def preprocess_features(features):\n",
    "    \"\"\"Row-normalize feature matrix and convert to tuple representation\"\"\"\n",
    "    #行归一化特征矩阵并转换为元组表示\n",
    "    rowsum = np.array(features.sum(1))\n",
    "    r_inv = np.power(rowsum, -1).flatten()\n",
    "    r_inv[np.isinf(r_inv)] = 0.\n",
    "    r_mat_inv = sp.diags(r_inv)\n",
    "    features = r_mat_inv.dot(features)\n",
    "    return sparse_to_tuple(features)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 124,
   "metadata": {},
   "outputs": [],
   "source": [
    "def sparse_to_tuple(sparse_mx):\n",
    "    \"\"\"Convert sparse matrix to tuple representation.\"\"\"\n",
    "    def to_tuple(mx):\n",
    "        if not sp.isspmatrix_coo(mx):\n",
    "            mx = mx.tocoo()\n",
    "        coords = np.vstack((mx.row, mx.col)).transpose()\n",
    "        values = mx.data\n",
    "        shape = mx.shape\n",
    "        return coords, values, shape\n",
    "\n",
    "    if isinstance(sparse_mx, list):\n",
    "        for i in range(len(sparse_mx)):\n",
    "            sparse_mx[i] = to_tuple(sparse_mx[i])\n",
    "    else:\n",
    "        sparse_mx = to_tuple(sparse_mx)\n",
    "\n",
    "    return sparse_mx"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 125,
   "metadata": {},
   "outputs": [],
   "source": [
    "features = preprocess_features(features)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 137,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(array([[   0, 1997],\n",
       "        [   0, 1990],\n",
       "        [   0, 1989],\n",
       "        ...,\n",
       "        [9104,   11],\n",
       "        [9104,    1],\n",
       "        [9104,    0]], dtype=int32),\n",
       " array([0.00149701, 0.00149701, 0.00149701, ..., 0.00453858, 0.00100857,\n",
       "        0.00050429]),\n",
       " (9105, 2000))"
      ]
     },
     "execution_count": 137,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#coords坐标, values值, shape形状\n",
    "features"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 138,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([0.00149701, 0.00149701, 0.00149701, ..., 0.00453858, 0.00100857,\n",
       "       0.00050429])"
      ]
     },
     "execution_count": 138,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "features[1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 139,
   "metadata": {},
   "outputs": [],
   "source": [
    "#' 5) Given cell type, generate three sets of labels with the same dimension\n",
    "labels_tr = labels_train.flatten()\n",
    "labels_va = labels_val.flatten()\n",
    "labels_te = labels_test.flatten()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 140,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array(['alpha', 'alpha', 'alpha', ..., 'beta', 'beta', 'ductal'],\n",
       "      dtype=object)"
      ]
     },
     "execution_count": 140,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "labels_tr"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 141,
   "metadata": {},
   "outputs": [],
   "source": [
    "labels = np.concatenate(\n",
    "    [np.concatenate([labels_tr, labels_va]), labels_te])\n",
    "Labels = pd.DataFrame(labels)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 147,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>0</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>alpha</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>alpha</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>alpha</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>alpha</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>alpha</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9100</th>\n",
       "      <td>quiescent_stellate</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9101</th>\n",
       "      <td>quiescent_stellate</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9102</th>\n",
       "      <td>quiescent_stellate</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9103</th>\n",
       "      <td>quiescent_stellate</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9104</th>\n",
       "      <td>quiescent_stellate</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>9105 rows × 1 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                       0\n",
       "0                  alpha\n",
       "1                  alpha\n",
       "2                  alpha\n",
       "3                  alpha\n",
       "4                  alpha\n",
       "...                  ...\n",
       "9100  quiescent_stellate\n",
       "9101  quiescent_stellate\n",
       "9102  quiescent_stellate\n",
       "9103  quiescent_stellate\n",
       "9104  quiescent_stellate\n",
       "\n",
       "[9105 rows x 1 columns]"
      ]
     },
     "execution_count": 147,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Labels"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 148,
   "metadata": {},
   "outputs": [],
   "source": [
    "#记录真实标记\n",
    "true_label = Labels"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 151,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array(['alpha', 'beta', 'delta', 'ductal', 'endothelial', 'gamma',\n",
       "       'macrophage', 'quiescent_stellate'], dtype=object)"
      ]
     },
     "execution_count": 151,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#' convert list to binary matrix\n",
    "# 获取标签的分类，8种\n",
    "uniq = np.unique(Labels.values)\n",
    "uniq"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 152,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['alpha',\n",
       " 'beta',\n",
       " 'delta',\n",
       " 'ductal',\n",
       " 'endothelial',\n",
       " 'gamma',\n",
       " 'macrophage',\n",
       " 'quiescent_stellate']"
      ]
     },
     "execution_count": 152,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "types"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 153,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'alpha': 0,\n",
       " 'beta': 1,\n",
       " 'delta': 2,\n",
       " 'ductal': 3,\n",
       " 'endothelial': 4,\n",
       " 'gamma': 5,\n",
       " 'macrophage': 6,\n",
       " 'quiescent_stellate': 7}"
      ]
     },
     "execution_count": 153,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#利用rename字典记录标签分类\n",
    "rename = {}\n",
    "for line in range(0, len(types)):\n",
    "    key = types[line]\n",
    "    rename[key] = int(line)\n",
    "rename"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 154,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>0</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>alpha</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>alpha</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>alpha</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>alpha</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>alpha</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9100</th>\n",
       "      <td>quiescent_stellate</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9101</th>\n",
       "      <td>quiescent_stellate</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9102</th>\n",
       "      <td>quiescent_stellate</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9103</th>\n",
       "      <td>quiescent_stellate</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9104</th>\n",
       "      <td>quiescent_stellate</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>9105 rows × 1 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                       0\n",
       "0                  alpha\n",
       "1                  alpha\n",
       "2                  alpha\n",
       "3                  alpha\n",
       "4                  alpha\n",
       "...                  ...\n",
       "9100  quiescent_stellate\n",
       "9101  quiescent_stellate\n",
       "9102  quiescent_stellate\n",
       "9103  quiescent_stellate\n",
       "9104  quiescent_stellate\n",
       "\n",
       "[9105 rows x 1 columns]"
      ]
     },
     "execution_count": 154,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Labels"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 155,
   "metadata": {},
   "outputs": [],
   "source": [
    "#将标签名称替换为可以key\n",
    "Label1 = Labels.replace(rename)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 156,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>0</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9100</th>\n",
       "      <td>7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9101</th>\n",
       "      <td>7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9102</th>\n",
       "      <td>7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9103</th>\n",
       "      <td>7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9104</th>\n",
       "      <td>7</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>9105 rows × 1 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "      0\n",
       "0     0\n",
       "1     0\n",
       "2     0\n",
       "3     0\n",
       "4     0\n",
       "...  ..\n",
       "9100  7\n",
       "9101  7\n",
       "9102  7\n",
       "9103  7\n",
       "9104  7\n",
       "\n",
       "[9105 rows x 1 columns]"
      ]
     },
     "execution_count": 156,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Label1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 157,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[0],\n",
       "       [0],\n",
       "       [0],\n",
       "       ...,\n",
       "       [7],\n",
       "       [7],\n",
       "       [7]])"
      ]
     },
     "execution_count": 157,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Label1.values"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 158,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[[0],\n",
       " [0],\n",
       " [0],\n",
       " [0],\n",
       " [0],\n",
       " [0],\n",
       " [0],\n",
       " [0],\n",
       " [0],\n",
       " [0],\n",
       " [0],\n",
       " [0],\n",
       " [0],\n",
       " [0],\n",
       " [0],\n",
       " [0],\n",
       " [0],\n",
       " [0],\n",
       " [0],\n",
       " [0],\n",
       " [0],\n",
       " [0],\n",
       " [0],\n",
       " [0],\n",
       " [0],\n",
       " [0],\n",
       " [0],\n",
       " [0],\n",
       " [0],\n",
       " [0],\n",
       " [0],\n",
       " [0],\n",
       " [0],\n",
       " [0],\n",
       " [0],\n",
       " [0],\n",
       " [0],\n",
       " [0],\n",
       " [0],\n",
       " [0],\n",
       " [0],\n",
       " [0],\n",
       " [0],\n",
       " [0],\n",
       " [0],\n",
       " [0],\n",
       " [0],\n",
       " [0],\n",
       " [0],\n",
       " [0],\n",
       " [0],\n",
       " [0],\n",
       " [0],\n",
       " [0],\n",
       " [0],\n",
       " [0],\n",
       " [0],\n",
       " [0],\n",
       " [0],\n",
       " [0],\n",
       " [0],\n",
       " [0],\n",
       " [0],\n",
       " [0],\n",
       " [0],\n",
       " [0],\n",
       " [0],\n",
       " [0],\n",
       " [0],\n",
       " [0],\n",
       " [0],\n",
       " [0],\n",
       " [0],\n",
       " [0],\n",
       " [0],\n",
       " [0],\n",
       " [0],\n",
       " [0],\n",
       " [0],\n",
       " [0],\n",
       " [0],\n",
       " [0],\n",
       " [0],\n",
       " [0],\n",
       " [0],\n",
       " [0],\n",
       " [0],\n",
       " [0],\n",
       " [0],\n",
       " [0],\n",
       " [0],\n",
       " [0],\n",
       " [0],\n",
       " [0],\n",
       " [0],\n",
       " [0],\n",
       " [0],\n",
       " [0],\n",
       " [0],\n",
       " [0],\n",
       " [0],\n",
       " [0],\n",
       " [0],\n",
       " [0],\n",
       " [0],\n",
       " [0],\n",
       " [0],\n",
       " [0],\n",
       " [0],\n",
       " [0],\n",
       " [0],\n",
       " [0],\n",
       " [0],\n",
       " [0],\n",
       " [0],\n",
       " [0],\n",
       " [0],\n",
       " [0],\n",
       " [0],\n",
       " [0],\n",
       " [0],\n",
       " [0],\n",
       " [0],\n",
       " [0],\n",
       " [0],\n",
       " [0],\n",
       " [0],\n",
       " [0],\n",
       " [0],\n",
       " [0],\n",
       " [0],\n",
       " [0],\n",
       " [0],\n",
       " [0],\n",
       " [0],\n",
       " [0],\n",
       " [0],\n",
       " [0],\n",
       " [0],\n",
       " [0],\n",
       " [0],\n",
       " [0],\n",
       " [0],\n",
       " [0],\n",
       " [0],\n",
       " [0],\n",
       " [0],\n",
       " [0],\n",
       " [0],\n",
       " [0],\n",
       " [0],\n",
       " [0],\n",
       " [0],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [1],\n",
       " [2],\n",
       " [2],\n",
       " [2],\n",
       " [2],\n",
       " [2],\n",
       " [2],\n",
       " [2],\n",
       " [2],\n",
       " [2],\n",
       " [2],\n",
       " [2],\n",
       " [2],\n",
       " [2],\n",
       " [2],\n",
       " [2],\n",
       " [2],\n",
       " [2],\n",
       " [2],\n",
       " [2],\n",
       " [2],\n",
       " [2],\n",
       " [2],\n",
       " [2],\n",
       " [2],\n",
       " [2],\n",
       " [2],\n",
       " [2],\n",
       " [2],\n",
       " [2],\n",
       " [2],\n",
       " [2],\n",
       " [2],\n",
       " [2],\n",
       " [2],\n",
       " [2],\n",
       " [2],\n",
       " [2],\n",
       " [2],\n",
       " [2],\n",
       " [2],\n",
       " [2],\n",
       " [2],\n",
       " [2],\n",
       " [2],\n",
       " [2],\n",
       " [2],\n",
       " [2],\n",
       " [2],\n",
       " [2],\n",
       " [2],\n",
       " [2],\n",
       " [2],\n",
       " [2],\n",
       " [2],\n",
       " [2],\n",
       " [2],\n",
       " [2],\n",
       " [2],\n",
       " [2],\n",
       " [2],\n",
       " [2],\n",
       " [2],\n",
       " [2],\n",
       " [2],\n",
       " [2],\n",
       " [2],\n",
       " [2],\n",
       " [2],\n",
       " [2],\n",
       " [2],\n",
       " [2],\n",
       " [2],\n",
       " [2],\n",
       " [2],\n",
       " [2],\n",
       " [2],\n",
       " [2],\n",
       " [2],\n",
       " [2],\n",
       " [2],\n",
       " [2],\n",
       " [2],\n",
       " [2],\n",
       " [2],\n",
       " [2],\n",
       " [2],\n",
       " [2],\n",
       " [2],\n",
       " [2],\n",
       " [2],\n",
       " [2],\n",
       " [2],\n",
       " [2],\n",
       " [2],\n",
       " [2],\n",
       " [2],\n",
       " [2],\n",
       " [2],\n",
       " [2],\n",
       " [2],\n",
       " [2],\n",
       " [2],\n",
       " [2],\n",
       " [2],\n",
       " [2],\n",
       " [2],\n",
       " [2],\n",
       " [2],\n",
       " [2],\n",
       " [2],\n",
       " [2],\n",
       " [2],\n",
       " [2],\n",
       " [2],\n",
       " [2],\n",
       " [2],\n",
       " [2],\n",
       " [2],\n",
       " [2],\n",
       " [2],\n",
       " [2],\n",
       " [2],\n",
       " [2],\n",
       " [2],\n",
       " ...]"
      ]
     },
     "execution_count": 158,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#将标签的值存入list\n",
    "indices = np.array(Label1.values, dtype='int').tolist()\n",
    "indices"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 162,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "9105"
      ]
     },
     "execution_count": 162,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(indices)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 166,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[7]"
      ]
     },
     "execution_count": 166,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "indices[9104]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 159,
   "metadata": {},
   "outputs": [],
   "source": [
    "#转成一个列表\n",
    "indice = [item for sublist in indices for item in sublist]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 164,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 2,\n",
       " 2,\n",
       " 2,\n",
       " 2,\n",
       " 2,\n",
       " 2,\n",
       " 2,\n",
       " 2,\n",
       " 2,\n",
       " 2,\n",
       " 2,\n",
       " 2,\n",
       " 2,\n",
       " 2,\n",
       " 2,\n",
       " 2,\n",
       " 2,\n",
       " 2,\n",
       " 2,\n",
       " 2,\n",
       " 2,\n",
       " 2,\n",
       " 2,\n",
       " 2,\n",
       " 2,\n",
       " 2,\n",
       " 2,\n",
       " 2,\n",
       " 2,\n",
       " 2,\n",
       " 2,\n",
       " 2,\n",
       " 2,\n",
       " 2,\n",
       " 2,\n",
       " 2,\n",
       " 2,\n",
       " 2,\n",
       " 2,\n",
       " 2,\n",
       " 2,\n",
       " 2,\n",
       " 2,\n",
       " 2,\n",
       " 2,\n",
       " 2,\n",
       " 2,\n",
       " 2,\n",
       " 2,\n",
       " 2,\n",
       " 2,\n",
       " 2,\n",
       " 2,\n",
       " 2,\n",
       " 2,\n",
       " 2,\n",
       " 2,\n",
       " 2,\n",
       " 2,\n",
       " 2,\n",
       " 2,\n",
       " 2,\n",
       " 2,\n",
       " 2,\n",
       " 2,\n",
       " 2,\n",
       " 2,\n",
       " 2,\n",
       " 2,\n",
       " 2,\n",
       " 2,\n",
       " 2,\n",
       " 2,\n",
       " 2,\n",
       " 2,\n",
       " 2,\n",
       " 2,\n",
       " 2,\n",
       " 2,\n",
       " 2,\n",
       " 2,\n",
       " 2,\n",
       " 2,\n",
       " 2,\n",
       " 2,\n",
       " 2,\n",
       " 2,\n",
       " 2,\n",
       " 2,\n",
       " 2,\n",
       " 2,\n",
       " 2,\n",
       " 2,\n",
       " 2,\n",
       " 2,\n",
       " 2,\n",
       " 2,\n",
       " 2,\n",
       " 2,\n",
       " 2,\n",
       " 2,\n",
       " 2,\n",
       " 2,\n",
       " 2,\n",
       " 2,\n",
       " 2,\n",
       " 2,\n",
       " 2,\n",
       " 2,\n",
       " 2,\n",
       " 2,\n",
       " 2,\n",
       " 2,\n",
       " 2,\n",
       " 2,\n",
       " 2,\n",
       " 2,\n",
       " 2,\n",
       " 2,\n",
       " 2,\n",
       " 2,\n",
       " 2,\n",
       " 2,\n",
       " 2,\n",
       " ...]"
      ]
     },
     "execution_count": 164,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "indice"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 167,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "7"
      ]
     },
     "execution_count": 167,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "indice[9104]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## scipy.sparse.csr_matrix例子\n",
    "indptr = np.array([0, 2, 3, 6])#indptr记录每行第一个非0元和最后一个非0元换行位置\n",
    "indices = np.array([0, 2, 2, 0, 1, 2])#每行列索引\n",
    "data = np.array([1, 2, 3, 4, 5, 6])#数据\n",
    "csr_matrix((data, indices, indptr), shape=(3, 3)).toarray()\n",
    "array([[1, 0, 2],\n",
    "       [0, 0, 3],\n",
    "       [4, 5, 6]])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 172,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<9105x8 sparse matrix of type '<class 'numpy.float64'>'\n",
       "\twith 9105 stored elements in Compressed Sparse Row format>"
      ]
     },
     "execution_count": 172,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#' convert list to binary matrix\n",
    "#每个值的索引\n",
    "indptr = range(len(indice) + 1)\n",
    "#每个值\n",
    "dat = np.ones(len(indice))\n",
    "binary_label = scipy.sparse.csr_matrix((dat, indice, indptr))\n",
    "binary_label"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 173,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[1., 0., 0., ..., 0., 0., 0.],\n",
       "       [1., 0., 0., ..., 0., 0., 0.],\n",
       "       [1., 0., 0., ..., 0., 0., 0.],\n",
       "       ...,\n",
       "       [0., 0., 0., ..., 0., 0., 1.],\n",
       "       [0., 0., 0., ..., 0., 0., 1.],\n",
       "       [0., 0., 0., ..., 0., 0., 1.]])"
      ]
     },
     "execution_count": 173,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#转成one-hot编码\n",
    "binary_label.toarray()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 174,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<9105x8 sparse matrix of type '<class 'numpy.float64'>'\n",
       "\twith 9105 stored elements in Compressed Sparse Row format>"
      ]
     },
     "execution_count": 174,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "binary_label"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 175,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[1., 0., 0., ..., 0., 0., 0.],\n",
       "       [1., 0., 0., ..., 0., 0., 0.],\n",
       "       [1., 0., 0., ..., 0., 0., 0.],\n",
       "       ...,\n",
       "       [0., 0., 0., ..., 0., 0., 1.],\n",
       "       [0., 0., 0., ..., 0., 0., 1.],\n",
       "       [0., 0., 0., ..., 0., 0., 1.]])"
      ]
     },
     "execution_count": 175,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#' new label with binary values\n",
    "# 转成稠密矩阵\n",
    "new_label = np.array(binary_label.todense())\n",
    "new_label"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 180,
   "metadata": {},
   "outputs": [],
   "source": [
    "#训练，预测，验证，测试集的索引范围\n",
    "idx_train = range(M)\n",
    "idx_pred = range(M, len(labels_tr))\n",
    "idx_val = range(len(labels_tr), len(labels_tr) + len(labels_va))\n",
    "idx_test = range(len(labels_tr) + len(labels_va),len(labels_tr) + len(labels_va) + len(labels_te))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 181,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "range(0, 1483)"
      ]
     },
     "execution_count": 181,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "idx_train"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 182,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "range(1483, 8747)"
      ]
     },
     "execution_count": 182,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "idx_pred"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 183,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "range(8747, 8917)"
      ]
     },
     "execution_count": 183,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "idx_val"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 184,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "range(8917, 9105)"
      ]
     },
     "execution_count": 184,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "idx_test"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 185,
   "metadata": {},
   "outputs": [],
   "source": [
    "#将列表里标记为1的转为True\n",
    "def sample_mask(idx, l):\n",
    "    \"\"\"Create mask.\"\"\"\n",
    "    mask = np.zeros(l)\n",
    "    mask[idx] = 1\n",
    "    return np.array(mask, dtype=np.bool)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 186,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "9105"
      ]
     },
     "execution_count": 186,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "new_label.shape[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 187,
   "metadata": {},
   "outputs": [],
   "source": [
    "train_mask = sample_mask(idx_train, new_label.shape[0])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 189,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([ True,  True,  True, ..., False, False, False])"
      ]
     },
     "execution_count": 189,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "train_mask"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 192,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([ True,  True,  True, ...,  True,  True,  True])"
      ]
     },
     "execution_count": 192,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "train_mask[0:1483]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 193,
   "metadata": {},
   "outputs": [],
   "source": [
    "pred_mask = sample_mask(idx_pred, new_label.shape[0])\n",
    "val_mask = sample_mask(idx_val, new_label.shape[0])\n",
    "test_mask = sample_mask(idx_test, new_label.shape[0])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 195,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([ True,  True,  True, ...,  True,  True,  True])"
      ]
     },
     "execution_count": 195,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pred_mask[1483:8747]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 196,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([ True,  True,  True,  True,  True,  True,  True,  True,  True,\n",
       "        True,  True,  True,  True,  True,  True,  True,  True,  True,\n",
       "        True,  True,  True,  True,  True,  True,  True,  True,  True,\n",
       "        True,  True,  True,  True,  True,  True,  True,  True,  True,\n",
       "        True,  True,  True,  True,  True,  True,  True,  True,  True,\n",
       "        True,  True,  True,  True,  True,  True,  True,  True,  True,\n",
       "        True,  True,  True,  True,  True,  True,  True,  True,  True,\n",
       "        True,  True,  True,  True,  True,  True,  True,  True,  True,\n",
       "        True,  True,  True,  True,  True,  True,  True,  True,  True,\n",
       "        True,  True,  True,  True,  True,  True,  True,  True,  True,\n",
       "        True,  True,  True,  True,  True,  True,  True,  True,  True,\n",
       "        True,  True,  True,  True,  True,  True,  True,  True,  True,\n",
       "        True,  True,  True,  True,  True,  True,  True,  True,  True,\n",
       "        True,  True,  True,  True,  True,  True,  True,  True,  True,\n",
       "        True,  True,  True,  True,  True,  True,  True,  True,  True,\n",
       "        True,  True,  True,  True,  True,  True,  True,  True,  True,\n",
       "        True,  True,  True,  True,  True,  True,  True,  True,  True,\n",
       "        True,  True,  True,  True,  True,  True,  True,  True,  True,\n",
       "        True,  True,  True,  True,  True,  True,  True,  True])"
      ]
     },
     "execution_count": 196,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "val_mask[8747:8917]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 197,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([ True,  True,  True,  True,  True,  True,  True,  True,  True,\n",
       "        True,  True,  True,  True,  True,  True,  True,  True,  True,\n",
       "        True,  True,  True,  True,  True,  True,  True,  True,  True,\n",
       "        True,  True,  True,  True,  True,  True,  True,  True,  True,\n",
       "        True,  True,  True,  True,  True,  True,  True,  True,  True,\n",
       "        True,  True,  True,  True,  True,  True,  True,  True,  True,\n",
       "        True,  True,  True,  True,  True,  True,  True,  True,  True,\n",
       "        True,  True,  True,  True,  True,  True,  True,  True,  True,\n",
       "        True,  True,  True,  True,  True,  True,  True,  True,  True,\n",
       "        True,  True,  True,  True,  True,  True,  True,  True,  True,\n",
       "        True,  True,  True,  True,  True,  True,  True,  True,  True,\n",
       "        True,  True,  True,  True,  True,  True,  True,  True,  True,\n",
       "        True,  True,  True,  True,  True,  True,  True,  True,  True,\n",
       "        True,  True,  True,  True,  True,  True,  True,  True,  True,\n",
       "        True,  True,  True,  True,  True,  True,  True,  True,  True,\n",
       "        True,  True,  True,  True,  True,  True,  True,  True,  True,\n",
       "        True,  True,  True,  True,  True,  True,  True,  True,  True,\n",
       "        True,  True,  True,  True,  True,  True,  True,  True,  True,\n",
       "        True,  True,  True,  True,  True,  True,  True,  True,  True,\n",
       "        True,  True,  True,  True,  True,  True,  True,  True,  True,\n",
       "        True,  True,  True,  True,  True,  True,  True,  True])"
      ]
     },
     "execution_count": 197,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "test_mask[8917:9105]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 198,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(9105, 8)"
      ]
     },
     "execution_count": 198,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "new_label.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 199,
   "metadata": {},
   "outputs": [],
   "source": [
    "labels_binary_train = np.zeros(new_label.shape)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 203,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[0., 0., 0., ..., 0., 0., 0.],\n",
       "       [0., 0., 0., ..., 0., 0., 0.],\n",
       "       [0., 0., 0., ..., 0., 0., 0.],\n",
       "       ...,\n",
       "       [0., 0., 0., ..., 0., 0., 0.],\n",
       "       [0., 0., 0., ..., 0., 0., 0.],\n",
       "       [0., 0., 0., ..., 0., 0., 0.]])"
      ]
     },
     "execution_count": 203,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "labels_binary_train"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 204,
   "metadata": {},
   "outputs": [],
   "source": [
    "labels_binary_val = np.zeros(new_label.shape)\n",
    "labels_binary_test = np.zeros(new_label.shape)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 208,
   "metadata": {},
   "outputs": [],
   "source": [
    "#将标记为true的转为1\n",
    "labels_binary_train[train_mask, :] = new_label[train_mask, :]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 211,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[1., 0., 0., ..., 0., 0., 0.],\n",
       "       [1., 0., 0., ..., 0., 0., 0.],\n",
       "       [1., 0., 0., ..., 0., 0., 0.],\n",
       "       ...,\n",
       "       [0., 0., 0., ..., 0., 0., 0.],\n",
       "       [0., 0., 0., ..., 0., 0., 0.],\n",
       "       [0., 0., 0., ..., 0., 0., 0.]])"
      ]
     },
     "execution_count": 211,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "labels_binary_train"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 212,
   "metadata": {},
   "outputs": [],
   "source": [
    "labels_binary_val[val_mask, :] = new_label[val_mask, :]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 214,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[1., 0., 0., ..., 0., 0., 0.],\n",
       "       [1., 0., 0., ..., 0., 0., 0.],\n",
       "       [1., 0., 0., ..., 0., 0., 0.],\n",
       "       ...,\n",
       "       [0., 0., 0., ..., 0., 0., 1.],\n",
       "       [0., 0., 0., ..., 0., 0., 1.],\n",
       "       [0., 0., 0., ..., 0., 0., 1.]])"
      ]
     },
     "execution_count": 214,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "labels_binary_val[8747:8917]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 215,
   "metadata": {},
   "outputs": [],
   "source": [
    "labels_binary_test[test_mask, :] = new_label[test_mask, :]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 216,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[1., 0., 0., ..., 0., 0., 0.],\n",
       "       [1., 0., 0., ..., 0., 0., 0.],\n",
       "       [1., 0., 0., ..., 0., 0., 0.],\n",
       "       ...,\n",
       "       [0., 0., 0., ..., 0., 0., 1.],\n",
       "       [0., 0., 0., ..., 0., 0., 1.],\n",
       "       [0., 0., 0., ..., 0., 0., 1.]])"
      ]
     },
     "execution_count": 216,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "labels_binary_test[8917:9105]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## ----- construct adjacent matrix ---------"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 217,
   "metadata": {},
   "outputs": [],
   "source": [
    "id_graph1 = pd.read_csv('/Users/hufox/scGCN/scGCN/input/inter_graph.csv',index_col=0,sep=',')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 218,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>V1</th>\n",
       "      <th>V2</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>0</td>\n",
       "      <td>27</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1</td>\n",
       "      <td>618</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1</td>\n",
       "      <td>601</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1</td>\n",
       "      <td>755</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>1</td>\n",
       "      <td>1900</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1932</th>\n",
       "      <td>1838</td>\n",
       "      <td>950</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1933</th>\n",
       "      <td>1838</td>\n",
       "      <td>3027</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1934</th>\n",
       "      <td>1838</td>\n",
       "      <td>6031</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1935</th>\n",
       "      <td>1839</td>\n",
       "      <td>2789</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1936</th>\n",
       "      <td>1839</td>\n",
       "      <td>3948</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>1936 rows × 2 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "        V1    V2\n",
       "1        0    27\n",
       "2        1   618\n",
       "3        1   601\n",
       "4        1   755\n",
       "5        1  1900\n",
       "...    ...   ...\n",
       "1932  1838   950\n",
       "1933  1838  3027\n",
       "1934  1838  6031\n",
       "1935  1839  2789\n",
       "1936  1839  3948\n",
       "\n",
       "[1936 rows x 2 columns]"
      ]
     },
     "execution_count": 218,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "id_graph1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 219,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>V1</th>\n",
       "      <th>V2</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>0</td>\n",
       "      <td>1162</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>0</td>\n",
       "      <td>1120</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>1</td>\n",
       "      <td>23</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16804</th>\n",
       "      <td>7260</td>\n",
       "      <td>7260</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16805</th>\n",
       "      <td>7260</td>\n",
       "      <td>7235</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16806</th>\n",
       "      <td>7261</td>\n",
       "      <td>7261</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16807</th>\n",
       "      <td>7262</td>\n",
       "      <td>7262</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16808</th>\n",
       "      <td>7263</td>\n",
       "      <td>7263</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>16808 rows × 2 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "         V1    V2\n",
       "1         0     0\n",
       "2         0  1162\n",
       "3         0  1120\n",
       "4         1     1\n",
       "5         1    23\n",
       "...     ...   ...\n",
       "16804  7260  7260\n",
       "16805  7260  7235\n",
       "16806  7261  7261\n",
       "16807  7262  7262\n",
       "16808  7263  7263\n",
       "\n",
       "[16808 rows x 2 columns]"
      ]
     },
     "execution_count": 219,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "id_graph2 = pd.read_csv('/Users/hufox/scGCN/scGCN/input/intra_graph.csv',sep=',',index_col=0)\n",
    "id_graph2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 220,
   "metadata": {},
   "outputs": [],
   "source": [
    "#' --- map index ----\n",
    "# -1标记处代表人的细胞\n",
    "fake1 = np.array([-1] * len(lab_data2.index))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 221,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "7264"
      ]
     },
     "execution_count": 221,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(lab_data2.index)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 222,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([-1, -1, -1, ..., -1, -1, -1])"
      ]
     },
     "execution_count": 222,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "fake1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 223,
   "metadata": {},
   "outputs": [],
   "source": [
    "index1 = np.concatenate((data_train1.index, fake1, data_val1.index,\n",
    "                             data_test1.index)).flatten()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 225,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Int64Index([ 137, 1582, 1392,  992,  952,  880, 1699, 1037, 1339, 1635,\n",
       "            ...\n",
       "            1807,  724, 1401,  554, 1764,  651, 1092,  585, 1082,  703],\n",
       "           dtype='int64', length=1483)"
      ]
     },
     "execution_count": 225,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data_train1.index"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 226,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([-1, -1, -1, ..., -1, -1, -1])"
      ]
     },
     "execution_count": 226,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "index1[1483:1483+7264]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 227,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([ 137, 1582, 1392, ...,  108,  480,  382])"
      ]
     },
     "execution_count": 227,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "index1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 228,
   "metadata": {},
   "outputs": [],
   "source": [
    "fake2 = np.array([-1] * len(data_train1))\n",
    "fake3 = np.array([-1] * (len(data_val1) + len(data_test1)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 230,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1483"
      ]
     },
     "execution_count": 230,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(fake2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 231,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([-1, -1, -1, ..., -1, -1, -1])"
      ]
     },
     "execution_count": 231,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "fake2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 232,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "358"
      ]
     },
     "execution_count": 232,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(fake3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 233,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,\n",
       "       -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,\n",
       "       -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,\n",
       "       -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,\n",
       "       -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,\n",
       "       -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,\n",
       "       -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,\n",
       "       -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,\n",
       "       -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,\n",
       "       -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,\n",
       "       -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,\n",
       "       -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,\n",
       "       -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,\n",
       "       -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,\n",
       "       -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,\n",
       "       -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,\n",
       "       -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,\n",
       "       -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,\n",
       "       -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,\n",
       "       -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,\n",
       "       -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,\n",
       "       -1])"
      ]
     },
     "execution_count": 233,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "fake3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 237,
   "metadata": {},
   "outputs": [],
   "source": [
    "#find1训练集和验证集索引都设置为-1，中间人的索引设置为lab_data2.index[0,    1,    2, ..., 7261, 7262, 7263]\n",
    "find1 = np.concatenate((fake2, np.array(lab_data2.index), fake3)).flatten()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 238,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([-1, -1, -1, ..., -1, -1, -1])"
      ]
     },
     "execution_count": 238,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "find1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 239,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([   0,    1,    2, ..., 7261, 7262, 7263])"
      ]
     },
     "execution_count": 239,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "find1[1483:1483+7264]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## ' ---------------------------------------------\n",
    "## '  intra-graph 查询Q-Q图构建\n",
    "## ' ---------------------------------------------"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 240,
   "metadata": {},
   "outputs": [],
   "source": [
    "#将intra_graph.csv中的顶点标记转为find1中对应的索引，例如v1=0，在find1中的索引为1483\n",
    "#v1 v2\n",
    "#0  0\n",
    "#1483 1483\n",
    "id_grp1 = np.array([\n",
    "        np.concatenate((np.where(find1 == id_graph2.iloc[i, 1])[0],\n",
    "                        np.where(find1 == id_graph2.iloc[i, 0])[0]))\n",
    "        for i in range(len(id_graph2))\n",
    "    ])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 241,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[1483, 1483],\n",
       "       [2645, 1483],\n",
       "       [2603, 1483],\n",
       "       ...,\n",
       "       [8744, 8744],\n",
       "       [8745, 8745],\n",
       "       [8746, 8746]])"
      ]
     },
     "execution_count": 241,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "id_grp1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 243,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[1483, 1483],\n",
       "       [2645, 1483],\n",
       "       [2603, 1483],\n",
       "       ...,\n",
       "       [8744, 8744],\n",
       "       [8745, 8745],\n",
       "       [8746, 8746]])"
      ]
     },
     "execution_count": 243,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "id_grp1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 244,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[1483, 1483],\n",
       "       [1483, 2645],\n",
       "       [1483, 2603],\n",
       "       ...,\n",
       "       [8744, 8744],\n",
       "       [8745, 8745],\n",
       "       [8746, 8746]])"
      ]
     },
     "execution_count": 244,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#顶点v2 v1关系图\n",
    "id_grp2 = np.array([\n",
    "        np.concatenate((np.where(find1 == id_graph2.iloc[i, 0])[0],\n",
    "                        np.where(find1 == id_graph2.iloc[i, 1])[0]))\n",
    "        for i in range(len(id_graph2))\n",
    "    ])\n",
    "id_grp2"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## ' ---------------------------------------------\n",
    "## '  inter-graph 参考-查询R-Q图构建\n",
    "## ' ---------------------------------------------"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 245,
   "metadata": {},
   "outputs": [],
   "source": [
    "id_gp1 = np.array([\n",
    "        np.concatenate((np.where(find1 == id_graph1.iloc[i, 1])[0],\n",
    "                        np.where(index1 == id_graph1.iloc[i, 0])[0]))\n",
    "        for i in range(len(id_graph1))\n",
    "    ])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 246,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[1510,  465],\n",
       "       [2101, 1201],\n",
       "       [2084, 1201],\n",
       "       ...,\n",
       "       [7514, 1149],\n",
       "       [4272, 1469],\n",
       "       [5431, 1469]])"
      ]
     },
     "execution_count": 246,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "id_gp1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 247,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1936"
      ]
     },
     "execution_count": 247,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(id_gp1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 248,
   "metadata": {},
   "outputs": [],
   "source": [
    "id_gp2 = np.array([\n",
    "        np.concatenate((np.where(index1 == id_graph1.iloc[i, 0])[0],\n",
    "                        np.where(find1 == id_graph1.iloc[i, 1])[0]))\n",
    "        for i in range(len(id_graph1))\n",
    "    ])\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 249,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 465, 1510],\n",
       "       [1201, 2101],\n",
       "       [1201, 2084],\n",
       "       ...,\n",
       "       [1149, 7514],\n",
       "       [1469, 4272],\n",
       "       [1469, 5431]])"
      ]
     },
     "execution_count": 249,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "id_gp2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 250,
   "metadata": {},
   "outputs": [],
   "source": [
    "#构建单位矩阵\n",
    "matrix = np.identity(len(labels))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 255,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[1., 0., 0., ..., 0., 0., 0.],\n",
       "       [0., 1., 0., ..., 0., 0., 0.],\n",
       "       [0., 0., 1., ..., 0., 0., 0.],\n",
       "       ...,\n",
       "       [0., 0., 0., ..., 1., 0., 0.],\n",
       "       [0., 0., 0., ..., 0., 1., 0.],\n",
       "       [0., 0., 0., ..., 0., 0., 1.]])"
      ]
     },
     "execution_count": 255,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "matrix"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 261,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[1483, 1483],\n",
       "       [2645, 1483],\n",
       "       [2603, 1483],\n",
       "       ...,\n",
       "       [8744, 8744],\n",
       "       [8745, 8745],\n",
       "       [8746, 8746]])"
      ]
     },
     "execution_count": 261,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "id_grp1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 262,
   "metadata": {},
   "outputs": [],
   "source": [
    "#id_grp1.T 矩阵转置后对应位置设置为1\n",
    "matrix[tuple(id_grp1.T)] = 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 270,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1.0"
      ]
     },
     "execution_count": 270,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "matrix[8744][8744]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 277,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[1483, 1483, 1483, ..., 8744, 8745, 8746],\n",
       "       [1483, 2645, 2603, ..., 8744, 8745, 8746]])"
      ]
     },
     "execution_count": 277,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "id_grp2.T"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 278,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(array([1483, 1483, 1483, ..., 8744, 8745, 8746]),\n",
       " array([1483, 2645, 2603, ..., 8744, 8745, 8746]))"
      ]
     },
     "execution_count": 278,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "tuple(id_grp2.T)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 271,
   "metadata": {},
   "outputs": [],
   "source": [
    "matrix[tuple(id_grp2.T)] = 1\n",
    "matrix[tuple(id_gp1.T)] = 1\n",
    "matrix[tuple(id_gp2.T)] = 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 272,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[1., 0., 0., ..., 0., 0., 0.],\n",
       "       [0., 1., 0., ..., 0., 0., 0.],\n",
       "       [0., 0., 1., ..., 0., 0., 0.],\n",
       "       ...,\n",
       "       [0., 0., 0., ..., 1., 0., 0.],\n",
       "       [0., 0., 0., ..., 0., 1., 0.],\n",
       "       [0., 0., 0., ..., 0., 0., 1.]])"
      ]
     },
     "execution_count": 272,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "matrix"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 273,
   "metadata": {},
   "outputs": [],
   "source": [
    "#先按行遍历，再按列遍历，值为1的添加到字典values里，value为list，例如3: [3, 2675], 表示3节点和3、2675节点有1关系\n",
    "def graph(matrix):\n",
    "    adj = defaultdict(list)  # default value of int is 0\n",
    "    for i, row in enumerate(matrix):\n",
    "        for j, adjacent in enumerate(row):\n",
    "            if adjacent:\n",
    "                adj[i].append(j)\n",
    "        if adj[i].__len__ == 0:\n",
    "            adj[i] = []\n",
    "    return adj"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 284,
   "metadata": {},
   "outputs": [],
   "source": [
    "adj = graph(matrix)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 285,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "defaultdict(list,\n",
       "            {0: [0],\n",
       "             1: [1],\n",
       "             2: [2],\n",
       "             3: [3, 2675],\n",
       "             4: [4],\n",
       "             5: [5],\n",
       "             6: [6, 5234, 6899],\n",
       "             7: [7],\n",
       "             8: [8],\n",
       "             9: [9],\n",
       "             10: [10, 3325, 6928],\n",
       "             11: [11, 4945],\n",
       "             12: [12],\n",
       "             13: [13],\n",
       "             14: [14],\n",
       "             15: [15],\n",
       "             16: [16],\n",
       "             17: [17, 3325, 6952, 8337],\n",
       "             18: [18, 2038],\n",
       "             19: [19],\n",
       "             20: [20, 3502, 4658],\n",
       "             21: [21],\n",
       "             22: [22, 4149],\n",
       "             23: [23],\n",
       "             24: [24],\n",
       "             25: [25],\n",
       "             26: [26, 8094],\n",
       "             27: [27, 2299, 2525, 2789, 3606, 3649],\n",
       "             28: [28],\n",
       "             29: [29, 3458],\n",
       "             30: [30, 5662],\n",
       "             31: [31],\n",
       "             32: [32],\n",
       "             33: [33, 4894],\n",
       "             34: [34, 3537, 4661],\n",
       "             35: [35, 3716],\n",
       "             36: [36, 1630, 6341],\n",
       "             37: [37, 7920],\n",
       "             38: [38, 7538],\n",
       "             39: [39],\n",
       "             40: [40, 5361],\n",
       "             41: [41, 3394],\n",
       "             42: [42],\n",
       "             43: [43],\n",
       "             44: [44],\n",
       "             45: [45],\n",
       "             46: [46],\n",
       "             47: [47, 6564],\n",
       "             48: [48, 3661, 4735, 7879],\n",
       "             49: [49, 8558],\n",
       "             50: [50, 4658, 8469],\n",
       "             51: [51],\n",
       "             52: [52],\n",
       "             53: [53],\n",
       "             54: [54, 2913],\n",
       "             55: [55, 7832],\n",
       "             56: [56],\n",
       "             57: [57, 6437],\n",
       "             58: [58],\n",
       "             59: [59, 2051, 2844],\n",
       "             60: [60],\n",
       "             61: [61],\n",
       "             62: [62, 8427],\n",
       "             63: [63],\n",
       "             64: [64],\n",
       "             65: [65, 2815],\n",
       "             66: [66, 5670],\n",
       "             67: [67, 5639],\n",
       "             68: [68],\n",
       "             69: [69, 8185],\n",
       "             70: [70, 3788],\n",
       "             71: [71],\n",
       "             72: [72],\n",
       "             73: [73],\n",
       "             74: [74],\n",
       "             75: [75, 2360, 3728],\n",
       "             76: [76, 8394],\n",
       "             77: [77],\n",
       "             78: [78, 2195],\n",
       "             79: [79, 4658],\n",
       "             80: [80, 3305, 3311],\n",
       "             81: [81, 7331],\n",
       "             82: [82, 4705, 6878],\n",
       "             83: [83],\n",
       "             84: [84, 4466, 8245],\n",
       "             85: [85, 2252],\n",
       "             86: [86, 4671],\n",
       "             87: [87, 3394, 3441],\n",
       "             88: [88],\n",
       "             89: [89],\n",
       "             90: [90],\n",
       "             91: [91],\n",
       "             92: [92, 3517],\n",
       "             93: [93, 3358],\n",
       "             94: [94],\n",
       "             95: [95],\n",
       "             96: [96],\n",
       "             97: [97],\n",
       "             98: [98],\n",
       "             99: [99],\n",
       "             100: [100, 3517],\n",
       "             101: [101, 4449, 8337],\n",
       "             102: [102, 8444],\n",
       "             103: [103, 3495, 6036],\n",
       "             104: [104, 7874],\n",
       "             105: [105, 5234],\n",
       "             106: [106],\n",
       "             107: [107, 3668],\n",
       "             108: [108],\n",
       "             109: [109],\n",
       "             110: [110, 2277],\n",
       "             111: [111],\n",
       "             112: [112, 3394, 6928],\n",
       "             113: [113, 8087],\n",
       "             114: [114, 7097, 7634],\n",
       "             115: [115, 4390, 7182],\n",
       "             116: [116],\n",
       "             117: [117],\n",
       "             118: [118, 4140, 4661],\n",
       "             119: [119, 3265],\n",
       "             120: [120, 7146],\n",
       "             121: [121],\n",
       "             122: [122, 1491, 2673, 2808, 5614],\n",
       "             123: [123],\n",
       "             124: [124],\n",
       "             125: [125, 3356, 4460, 7638],\n",
       "             126: [126],\n",
       "             127: [127],\n",
       "             128: [128, 3779],\n",
       "             129: [129, 3249, 4661],\n",
       "             130: [130, 8122],\n",
       "             131: [131],\n",
       "             132: [132, 6391],\n",
       "             133: [133, 4327, 6928],\n",
       "             134: [134],\n",
       "             135: [135, 8525],\n",
       "             136: [136, 3325],\n",
       "             137: [137],\n",
       "             138: [138],\n",
       "             139: [139],\n",
       "             140: [140, 6896],\n",
       "             141: [141],\n",
       "             142: [142, 5825],\n",
       "             143: [143],\n",
       "             144: [144],\n",
       "             145: [145, 7565],\n",
       "             146: [146, 3334, 4945, 8291],\n",
       "             147: [147, 3325, 5670],\n",
       "             148: [148, 4703],\n",
       "             149: [149],\n",
       "             150: [150],\n",
       "             151: [151, 1630],\n",
       "             152: [152],\n",
       "             153: [153, 1483, 2581],\n",
       "             154: [154, 4474, 6345, 8514],\n",
       "             155: [155],\n",
       "             156: [156, 3805, 4683],\n",
       "             157: [157, 2062],\n",
       "             158: [158, 1749, 2272],\n",
       "             159: [159, 1636, 2708],\n",
       "             160: [160],\n",
       "             161: [161],\n",
       "             162: [162],\n",
       "             163: [163, 1720, 2791],\n",
       "             164: [164, 1493],\n",
       "             165: [165],\n",
       "             166: [166],\n",
       "             167: [167, 4346, 4433],\n",
       "             168: [168],\n",
       "             169: [169, 1643, 2112],\n",
       "             170: [170],\n",
       "             171: [171],\n",
       "             172: [172, 3133, 7471],\n",
       "             173: [173, 5532],\n",
       "             174: [174],\n",
       "             175: [175, 2102, 4138],\n",
       "             176: [176],\n",
       "             177: [177, 2108],\n",
       "             178: [178, 1593],\n",
       "             179: [179],\n",
       "             180: [180],\n",
       "             181: [181, 4369],\n",
       "             182: [182],\n",
       "             183: [183, 1943, 3100],\n",
       "             184: [184, 7940],\n",
       "             185: [185, 4560],\n",
       "             186: [186],\n",
       "             187: [187, 3758],\n",
       "             188: [188, 5167],\n",
       "             189: [189],\n",
       "             190: [190],\n",
       "             191: [191],\n",
       "             192: [192, 2856],\n",
       "             193: [193],\n",
       "             194: [194, 2289],\n",
       "             195: [195],\n",
       "             196: [196],\n",
       "             197: [197, 7503],\n",
       "             198: [198, 4169, 7116],\n",
       "             199: [199, 5601],\n",
       "             200: [200],\n",
       "             201: [201, 1845],\n",
       "             202: [202],\n",
       "             203: [203, 2784, 4368, 4501],\n",
       "             204: [204, 5419],\n",
       "             205: [205, 4211, 4492],\n",
       "             206: [206],\n",
       "             207: [207, 1512, 2045, 2634],\n",
       "             208: [208],\n",
       "             209: [209, 3875, 8125],\n",
       "             210: [210, 2686],\n",
       "             211: [211, 7712],\n",
       "             212: [212, 3875],\n",
       "             213: [213, 7232],\n",
       "             214: [214, 3884],\n",
       "             215: [215, 1490, 5572],\n",
       "             216: [216, 1607, 2189],\n",
       "             217: [217, 2146],\n",
       "             218: [218],\n",
       "             219: [219, 3341],\n",
       "             220: [220, 3065],\n",
       "             221: [221],\n",
       "             222: [222, 2830],\n",
       "             223: [223],\n",
       "             224: [224],\n",
       "             225: [225],\n",
       "             226: [226, 1543, 1804],\n",
       "             227: [227],\n",
       "             228: [228, 8363],\n",
       "             229: [229, 1702],\n",
       "             230: [230, 1539, 2174, 6274, 6973],\n",
       "             231: [231, 3805, 4136],\n",
       "             232: [232],\n",
       "             233: [233],\n",
       "             234: [234, 2758],\n",
       "             235: [235],\n",
       "             236: [236],\n",
       "             237: [237],\n",
       "             238: [238, 4501],\n",
       "             239: [239, 4176],\n",
       "             240: [240],\n",
       "             241: [241],\n",
       "             242: [242],\n",
       "             243: [243, 5447],\n",
       "             244: [244, 6849, 6968, 7402],\n",
       "             245: [245, 2828, 4887],\n",
       "             246: [246, 1636, 4253],\n",
       "             247: [247, 4947, 6849],\n",
       "             248: [248, 2108, 2581, 2604],\n",
       "             249: [249],\n",
       "             250: [250, 1489],\n",
       "             251: [251],\n",
       "             252: [252],\n",
       "             253: [253, 3860, 4455],\n",
       "             254: [254],\n",
       "             255: [255, 3799, 3994],\n",
       "             256: [256, 6361, 6381],\n",
       "             257: [257, 3883, 5547],\n",
       "             258: [258, 2273, 2587],\n",
       "             259: [259, 1574],\n",
       "             260: [260],\n",
       "             261: [261, 1680, 2356],\n",
       "             262: [262, 4576],\n",
       "             263: [263],\n",
       "             264: [264, 2638],\n",
       "             265: [265],\n",
       "             266: [266, 5812],\n",
       "             267: [267, 2207, 5624],\n",
       "             268: [268, 5527, 6274],\n",
       "             269: [269, 2589, 2883],\n",
       "             270: [270, 2767, 2804],\n",
       "             271: [271],\n",
       "             272: [272, 7725],\n",
       "             273: [273, 2229, 6108],\n",
       "             274: [274],\n",
       "             275: [275, 4698],\n",
       "             276: [276],\n",
       "             277: [277, 6242],\n",
       "             278: [278],\n",
       "             279: [279, 2174],\n",
       "             280: [280],\n",
       "             281: [281, 2258],\n",
       "             282: [282, 1803],\n",
       "             283: [283],\n",
       "             284: [284],\n",
       "             285: [285],\n",
       "             286: [286, 3470],\n",
       "             287: [287],\n",
       "             288: [288],\n",
       "             289: [289, 3805, 3980, 4474],\n",
       "             290: [290],\n",
       "             291: [291, 7627],\n",
       "             292: [292],\n",
       "             293: [293],\n",
       "             294: [294],\n",
       "             295: [295, 2353],\n",
       "             296: [296, 2629],\n",
       "             297: [297, 5089],\n",
       "             298: [298],\n",
       "             299: [299],\n",
       "             300: [300, 5432, 7125],\n",
       "             301: [301],\n",
       "             302: [302, 6381],\n",
       "             303: [303, 3989, 4369],\n",
       "             304: [304],\n",
       "             305: [305],\n",
       "             306: [306],\n",
       "             307: [307],\n",
       "             308: [308],\n",
       "             309: [309],\n",
       "             310: [310, 1517],\n",
       "             311: [311],\n",
       "             312: [312, 2810],\n",
       "             313: [313],\n",
       "             314: [314, 7627, 8165],\n",
       "             315: [315, 1593, 2671],\n",
       "             316: [316, 5550],\n",
       "             317: [317],\n",
       "             318: [318],\n",
       "             319: [319, 3120],\n",
       "             320: [320],\n",
       "             321: [321, 7910],\n",
       "             322: [322, 7780],\n",
       "             323: [323, 7627, 7669],\n",
       "             324: [324, 6756, 7266],\n",
       "             325: [325, 1572],\n",
       "             326: [326],\n",
       "             327: [327],\n",
       "             328: [328, 5645, 5731],\n",
       "             329: [329],\n",
       "             330: [330],\n",
       "             331: [331],\n",
       "             332: [332, 3168],\n",
       "             333: [333, 2354],\n",
       "             334: [334],\n",
       "             335: [335],\n",
       "             336: [336],\n",
       "             337: [337, 4325],\n",
       "             338: [338],\n",
       "             339: [339],\n",
       "             340: [340, 2633],\n",
       "             341: [341, 1607],\n",
       "             342: [342, 1702],\n",
       "             343: [343, 5138],\n",
       "             344: [344, 3290],\n",
       "             345: [345],\n",
       "             346: [346],\n",
       "             347: [347],\n",
       "             348: [348, 7658, 7781],\n",
       "             349: [349, 7128],\n",
       "             350: [350, 3860],\n",
       "             351: [351],\n",
       "             352: [352, 2629, 3436],\n",
       "             353: [353, 4343],\n",
       "             354: [354, 3815, 4022, 4601],\n",
       "             355: [355, 5525],\n",
       "             356: [356],\n",
       "             357: [357],\n",
       "             358: [358, 4548, 6369],\n",
       "             359: [359],\n",
       "             360: [360, 2146, 3326],\n",
       "             361: [361, 7056, 7266, 7407, 7421],\n",
       "             362: [362],\n",
       "             363: [363],\n",
       "             364: [364, 2070, 2863],\n",
       "             365: [365],\n",
       "             366: [366, 2641, 4891],\n",
       "             367: [367],\n",
       "             368: [368],\n",
       "             369: [369, 1755, 2944],\n",
       "             370: [370],\n",
       "             371: [371, 1763],\n",
       "             372: [372],\n",
       "             373: [373, 8188],\n",
       "             374: [374],\n",
       "             375: [375],\n",
       "             376: [376, 4446],\n",
       "             377: [377],\n",
       "             378: [378, 7133],\n",
       "             379: [379],\n",
       "             380: [380, 2681],\n",
       "             381: [381, 2236],\n",
       "             382: [382],\n",
       "             383: [383],\n",
       "             384: [384, 7557, 7648, 7884],\n",
       "             385: [385],\n",
       "             386: [386, 2593, 2830],\n",
       "             387: [387, 3042],\n",
       "             388: [388, 1785],\n",
       "             389: [389],\n",
       "             390: [390, 4451, 8226],\n",
       "             391: [391],\n",
       "             392: [392],\n",
       "             393: [393, 4517],\n",
       "             394: [394, 6851],\n",
       "             395: [395, 4937, 5791, 6345],\n",
       "             396: [396, 2672, 3405],\n",
       "             397: [397, 2292],\n",
       "             398: [398, 8226],\n",
       "             399: [399, 1504, 2699],\n",
       "             400: [400, 1536],\n",
       "             401: [401],\n",
       "             402: [402],\n",
       "             403: [403],\n",
       "             404: [404, 5950],\n",
       "             405: [405],\n",
       "             406: [406],\n",
       "             407: [407, 6439, 7095],\n",
       "             408: [408, 2666],\n",
       "             409: [409, 4240, 6089],\n",
       "             410: [410, 1631, 2117],\n",
       "             411: [411],\n",
       "             412: [412, 2967],\n",
       "             413: [413, 2627],\n",
       "             414: [414, 5253, 6308],\n",
       "             415: [415, 2432],\n",
       "             416: [416],\n",
       "             417: [417, 2288],\n",
       "             418: [418],\n",
       "             419: [419, 7517],\n",
       "             420: [420],\n",
       "             421: [421, 1624, 2064, 2666],\n",
       "             422: [422, 3439],\n",
       "             423: [423, 2624, 2629],\n",
       "             424: [424],\n",
       "             425: [425, 6348],\n",
       "             426: [426, 4583],\n",
       "             427: [427, 3607],\n",
       "             428: [428, 3283, 3284, 3872],\n",
       "             429: [429],\n",
       "             430: [430],\n",
       "             431: [431],\n",
       "             432: [432],\n",
       "             433: [433],\n",
       "             434: [434],\n",
       "             435: [435],\n",
       "             436: [436],\n",
       "             437: [437, 7932],\n",
       "             438: [438],\n",
       "             439: [439],\n",
       "             440: [440, 1787],\n",
       "             441: [441, 2250, 2872, 5601, 7725],\n",
       "             442: [442],\n",
       "             443: [443, 6512, 6992],\n",
       "             444: [444],\n",
       "             445: [445],\n",
       "             446: [446, 1577, 2602],\n",
       "             447: [447, 3785],\n",
       "             448: [448, 7752],\n",
       "             449: [449],\n",
       "             450: [450, 2106],\n",
       "             451: [451],\n",
       "             452: [452, 2064, 2106, 2253, 5836],\n",
       "             453: [453],\n",
       "             454: [454],\n",
       "             455: [455],\n",
       "             456: [456, 2472, 2500, 3100],\n",
       "             457: [457, 2266],\n",
       "             458: [458],\n",
       "             459: [459],\n",
       "             460: [460, 8592],\n",
       "             461: [461, 1845, 2066],\n",
       "             462: [462, 2627],\n",
       "             463: [463, 6117],\n",
       "             464: [464],\n",
       "             465: [465, 1510],\n",
       "             466: [466, 4159, 4690],\n",
       "             467: [467, 5982, 8670],\n",
       "             468: [468, 5432, 6956],\n",
       "             469: [469, 3513, 3968, 8281],\n",
       "             470: [470, 3726, 6205, 6439, 7570],\n",
       "             471: [471],\n",
       "             472: [472],\n",
       "             473: [473],\n",
       "             474: [474],\n",
       "             475: [475, 1486, 5550, 6973],\n",
       "             476: [476],\n",
       "             477: [477, 6348],\n",
       "             478: [478, 1568],\n",
       "             479: [479, 5601, 6191],\n",
       "             480: [480, 3821],\n",
       "             481: [481],\n",
       "             482: [482],\n",
       "             483: [483],\n",
       "             484: [484, 5870, 6777, 7336],\n",
       "             485: [485],\n",
       "             486: [486],\n",
       "             487: [487, 4253],\n",
       "             488: [488],\n",
       "             489: [489],\n",
       "             490: [490],\n",
       "             491: [491],\n",
       "             492: [492, 2068, 2911],\n",
       "             493: [493, 5887, 6871],\n",
       "             494: [494],\n",
       "             495: [495],\n",
       "             496: [496, 6810, 7232],\n",
       "             497: [497, 2944],\n",
       "             498: [498, 7645, 8541],\n",
       "             499: [499, 2036, 2593],\n",
       "             500: [500, 7897],\n",
       "             501: [501],\n",
       "             502: [502],\n",
       "             503: [503, 5547],\n",
       "             504: [504],\n",
       "             505: [505, 2613, 6437],\n",
       "             506: [506],\n",
       "             507: [507],\n",
       "             508: [508, 7827],\n",
       "             509: [509, 2599, 2756],\n",
       "             510: [510, 6188],\n",
       "             511: [511],\n",
       "             512: [512, 2695],\n",
       "             513: [513],\n",
       "             514: [514],\n",
       "             515: [515],\n",
       "             516: [516],\n",
       "             517: [517],\n",
       "             518: [518],\n",
       "             519: [519, 3540],\n",
       "             520: [520],\n",
       "             521: [521, 3508, 4022],\n",
       "             522: [522],\n",
       "             523: [523],\n",
       "             524: [524],\n",
       "             525: [525, 5982],\n",
       "             526: [526],\n",
       "             527: [527, 5525, 6308, 7292],\n",
       "             528: [528],\n",
       "             529: [529],\n",
       "             530: [530, 6242],\n",
       "             531: [531],\n",
       "             532: [532, 6439],\n",
       "             533: [533, 2149, 2638],\n",
       "             534: [534],\n",
       "             535: [535, 2661],\n",
       "             536: [536, 1514, 2041],\n",
       "             537: [537],\n",
       "             538: [538, 3508, 3876],\n",
       "             539: [539],\n",
       "             540: [540],\n",
       "             541: [541, 1708],\n",
       "             542: [542],\n",
       "             543: [543],\n",
       "             544: [544],\n",
       "             545: [545],\n",
       "             546: [546],\n",
       "             547: [547],\n",
       "             548: [548],\n",
       "             549: [549, 2610, 6169],\n",
       "             550: [550, 7969],\n",
       "             551: [551],\n",
       "             552: [552, 2588, 7292],\n",
       "             553: [553, 2007],\n",
       "             554: [554, 2637],\n",
       "             555: [555, 3042],\n",
       "             556: [556],\n",
       "             557: [557],\n",
       "             558: [558],\n",
       "             559: [559],\n",
       "             560: [560, 4932],\n",
       "             561: [561, 2641, 6186],\n",
       "             562: [562, 2075],\n",
       "             563: [563],\n",
       "             564: [564, 3345, 3932, 3971],\n",
       "             565: [565, 1504, 2699],\n",
       "             566: [566, 7835],\n",
       "             567: [567, 1563],\n",
       "             568: [568],\n",
       "             569: [569, 6288],\n",
       "             570: [570, 2615, 2661],\n",
       "             571: [571, 5525],\n",
       "             572: [572, 4701],\n",
       "             573: [573, 1625],\n",
       "             574: [574],\n",
       "             575: [575],\n",
       "             576: [576],\n",
       "             577: [577, 6868],\n",
       "             578: [578],\n",
       "             579: [579, 2603],\n",
       "             580: [580, 2791],\n",
       "             581: [581, 5156, 5776],\n",
       "             582: [582, 4947],\n",
       "             583: [583, 3363, 7596],\n",
       "             584: [584],\n",
       "             585: [585, 1599, 2704],\n",
       "             586: [586, 5653, 6253, 7656],\n",
       "             587: [587],\n",
       "             588: [588, 6643],\n",
       "             589: [589, 1566, 2922],\n",
       "             590: [590],\n",
       "             591: [591, 7245, 7492],\n",
       "             592: [592, 6108],\n",
       "             593: [593],\n",
       "             594: [594],\n",
       "             595: [595, 2146],\n",
       "             596: [596, 1490, 2632],\n",
       "             597: [597, 3284],\n",
       "             598: [598, 2883, 5253],\n",
       "             599: [599, 7254],\n",
       "             600: [600, 2593, 2830],\n",
       "             601: [601],\n",
       "             602: [602, 3439],\n",
       "             603: [603],\n",
       "             604: [604],\n",
       "             605: [605],\n",
       "             606: [606],\n",
       "             607: [607, 1777],\n",
       "             608: [608, 2028, 2615, 2697],\n",
       "             609: [609],\n",
       "             610: [610],\n",
       "             611: [611],\n",
       "             612: [612],\n",
       "             613: [613, 6005],\n",
       "             614: [614],\n",
       "             615: [615],\n",
       "             616: [616, 2025],\n",
       "             617: [617, 2353],\n",
       "             618: [618, 3817, 3883, 4065],\n",
       "             619: [619, 6490],\n",
       "             620: [620, 2229, 6447, 6629],\n",
       "             621: [621, 2860],\n",
       "             622: [622],\n",
       "             623: [623],\n",
       "             624: [624, 1755, 4937],\n",
       "             625: [625, 2839, 4583],\n",
       "             626: [626, 3807],\n",
       "             627: [627],\n",
       "             628: [628, 2025, 2788, 3785],\n",
       "             629: [629],\n",
       "             630: [630, 4169],\n",
       "             631: [631],\n",
       "             632: [632, 7680, 8413, 8603],\n",
       "             633: [633, 1643],\n",
       "             634: [634, 1720],\n",
       "             635: [635, 6118],\n",
       "             636: [636, 2592, 2593, 2810],\n",
       "             637: [637],\n",
       "             638: [638],\n",
       "             639: [639],\n",
       "             640: [640, 7697],\n",
       "             641: [641],\n",
       "             642: [642],\n",
       "             643: [643, 2645],\n",
       "             644: [644],\n",
       "             645: [645],\n",
       "             646: [646],\n",
       "             647: [647],\n",
       "             648: [648],\n",
       "             649: [649],\n",
       "             650: [650],\n",
       "             651: [651],\n",
       "             652: [652],\n",
       "             653: [653],\n",
       "             654: [654, 6058],\n",
       "             655: [655, 4369],\n",
       "             656: [656],\n",
       "             657: [657, 2638],\n",
       "             658: [658],\n",
       "             659: [659],\n",
       "             660: [660],\n",
       "             661: [661, 1742],\n",
       "             662: [662],\n",
       "             663: [663, 1701],\n",
       "             664: [664, 3363, 4384, 5528, 8400],\n",
       "             665: [665, 1486],\n",
       "             666: [666, 2013, 2666, 3805],\n",
       "             667: [667, 1787],\n",
       "             668: [668],\n",
       "             669: [669],\n",
       "             670: [670, 4080],\n",
       "             671: [671, 7862],\n",
       "             672: [672, 3548],\n",
       "             673: [673],\n",
       "             674: [674],\n",
       "             675: [675],\n",
       "             676: [676, 1497],\n",
       "             677: [677, 7613, 8239, 8252],\n",
       "             678: [678, 7548],\n",
       "             679: [679, 1619, 2945, 6840],\n",
       "             680: [680],\n",
       "             681: [681, 8116],\n",
       "             682: [682, 3824],\n",
       "             683: [683],\n",
       "             684: [684, 2150],\n",
       "             685: [685],\n",
       "             686: [686, 5773, 6868],\n",
       "             687: [687, 2695],\n",
       "             688: [688],\n",
       "             689: [689, 2767, 2938],\n",
       "             690: [690],\n",
       "             691: [691],\n",
       "             692: [692],\n",
       "             693: [693],\n",
       "             694: [694, 3953],\n",
       "             695: [695],\n",
       "             696: [696],\n",
       "             697: [697, 7245],\n",
       "             698: [698, 7548],\n",
       "             699: [699],\n",
       "             700: [700],\n",
       "             701: [701],\n",
       "             702: [702, 2694, 3790, 3936, 4346],\n",
       "             703: [703],\n",
       "             704: [704],\n",
       "             705: [705, 6925],\n",
       "             706: [706, 3052],\n",
       "             707: [707, 5463, 8406],\n",
       "             708: [708, 2762, 2872],\n",
       "             709: [709, 3511, 8188],\n",
       "             710: [710],\n",
       "             711: [711, 6931],\n",
       "             712: [712, 2106],\n",
       "             713: [713, 5220],\n",
       "             714: [714, 5375],\n",
       "             715: [715, 1727, 3828, 4168],\n",
       "             716: [716, 3168],\n",
       "             717: [717, 3508],\n",
       "             718: [718],\n",
       "             719: [719],\n",
       "             720: [720, 3883, 3977, 5547],\n",
       "             721: [721, 3922],\n",
       "             722: [722],\n",
       "             723: [723],\n",
       "             724: [724],\n",
       "             725: [725],\n",
       "             726: [726, 1804, 2694],\n",
       "             727: [727, 3496],\n",
       "             728: [728],\n",
       "             729: [729, 2758, 6242],\n",
       "             730: [730, 3883, 4620],\n",
       "             731: [731, 1517],\n",
       "             732: [732, 5212],\n",
       "             733: [733, 1627, 1792],\n",
       "             734: [734, 2615],\n",
       "             735: [735],\n",
       "             736: [736, 1537],\n",
       "             737: [737],\n",
       "             738: [738],\n",
       "             739: [739, 2666],\n",
       "             740: [740, 7764, 7835],\n",
       "             741: [741, 1603, 3065],\n",
       "             742: [742],\n",
       "             743: [743, 6253],\n",
       "             744: [744, 3854],\n",
       "             745: [745],\n",
       "             746: [746, 1483, 2603, 2618],\n",
       "             747: [747],\n",
       "             748: [748],\n",
       "             749: [749],\n",
       "             750: [750],\n",
       "             751: [751, 7527, 7548, 7835, 7862],\n",
       "             752: [752, 7422],\n",
       "             753: [753],\n",
       "             754: [754],\n",
       "             755: [755],\n",
       "             756: [756],\n",
       "             757: [757],\n",
       "             758: [758, 3977],\n",
       "             759: [759, 6883],\n",
       "             760: [760, 3828, 3872],\n",
       "             761: [761],\n",
       "             762: [762],\n",
       "             763: [763, 5212, 6782],\n",
       "             764: [764, 5653, 6575],\n",
       "             765: [765, 2695],\n",
       "             766: [766, 6163],\n",
       "             767: [767],\n",
       "             768: [768],\n",
       "             769: [769, 4444],\n",
       "             770: [770, 5550],\n",
       "             771: [771, 1616, 2168],\n",
       "             772: [772, 4412],\n",
       "             773: [773],\n",
       "             774: [774],\n",
       "             775: [775],\n",
       "             776: [776, 7270],\n",
       "             777: [777, 1797, 2141, 2668],\n",
       "             778: [778],\n",
       "             779: [779, 7421],\n",
       "             780: [780, 5527],\n",
       "             781: [781],\n",
       "             782: [782, 1514],\n",
       "             783: [783],\n",
       "             784: [784],\n",
       "             785: [785],\n",
       "             786: [786, 3367],\n",
       "             787: [787, 6186],\n",
       "             788: [788, 5647, 6439],\n",
       "             789: [789],\n",
       "             790: [790],\n",
       "             791: [791, 2922],\n",
       "             792: [792],\n",
       "             793: [793, 5989],\n",
       "             794: [794],\n",
       "             795: [795, 7892],\n",
       "             796: [796, 1651, 1720],\n",
       "             797: [797],\n",
       "             798: [798],\n",
       "             799: [799],\n",
       "             800: [800],\n",
       "             801: [801],\n",
       "             802: [802],\n",
       "             803: [803, 4169],\n",
       "             804: [804, 2146, 4914],\n",
       "             805: [805, 8510],\n",
       "             806: [806, 1513, 1552],\n",
       "             807: [807, 1490, 7613, 7680],\n",
       "             808: [808],\n",
       "             809: [809, 2136, 4346],\n",
       "             810: [810],\n",
       "             811: [811],\n",
       "             812: [812],\n",
       "             813: [813],\n",
       "             814: [814, 1504, 2653, 4474],\n",
       "             815: [815],\n",
       "             816: [816],\n",
       "             817: [817, 3851],\n",
       "             818: [818, 8633],\n",
       "             819: [819, 2357, 6005],\n",
       "             820: [820],\n",
       "             821: [821],\n",
       "             822: [822, 6068],\n",
       "             823: [823, 3341],\n",
       "             824: [824, 8188],\n",
       "             825: [825, 7254],\n",
       "             826: [826, 5525, 5719, 6203],\n",
       "             827: [827],\n",
       "             828: [828, 2112, 2638, 7548],\n",
       "             829: [829],\n",
       "             830: [830],\n",
       "             831: [831, 4006, 4168],\n",
       "             832: [832, 7161],\n",
       "             833: [833],\n",
       "             834: [834],\n",
       "             835: [835, 1726],\n",
       "             836: [836, 2041, 2879],\n",
       "             837: [837, 2253],\n",
       "             838: [838],\n",
       "             839: [839],\n",
       "             840: [840, 1754, 2491],\n",
       "             841: [841, 2856],\n",
       "             842: [842, 7555, 7881],\n",
       "             843: [843, 2028],\n",
       "             844: [844],\n",
       "             845: [845, 2636],\n",
       "             846: [846, 6345],\n",
       "             847: [847, 1497],\n",
       "             848: [848, 2070, 2699, 3439],\n",
       "             849: [849, 6186],\n",
       "             850: [850],\n",
       "             851: [851],\n",
       "             852: [852, 3299, 5555],\n",
       "             853: [853],\n",
       "             854: [854],\n",
       "             855: [855, 7892],\n",
       "             856: [856],\n",
       "             857: [857],\n",
       "             858: [858],\n",
       "             859: [859],\n",
       "             860: [860, 6643, 6756],\n",
       "             861: [861, 7835],\n",
       "             862: [862, 2337],\n",
       "             863: [863, 5887],\n",
       "             864: [864, 3326, 7710],\n",
       "             865: [865, 2131, 2641],\n",
       "             866: [866],\n",
       "             867: [867, 2351, 2746],\n",
       "             868: [868],\n",
       "             869: [869, 6255, 6848],\n",
       "             870: [870],\n",
       "             871: [871],\n",
       "             872: [872],\n",
       "             873: [873, 3295],\n",
       "             874: [874],\n",
       "             875: [875],\n",
       "             876: [876],\n",
       "             877: [877],\n",
       "             878: [878, 7692],\n",
       "             879: [879],\n",
       "             880: [880, 1598],\n",
       "             881: [881],\n",
       "             882: [882],\n",
       "             883: [883, 2859, 4331],\n",
       "             884: [884],\n",
       "             885: [885],\n",
       "             886: [886],\n",
       "             887: [887, 2837],\n",
       "             888: [888, 2571, 4373],\n",
       "             889: [889, 2590],\n",
       "             890: [890, 7526],\n",
       "             891: [891, 2787, 3780],\n",
       "             892: [892, 2051],\n",
       "             893: [893, 1592, 4373],\n",
       "             894: [894],\n",
       "             895: [895],\n",
       "             896: [896, 8205],\n",
       "             897: [897],\n",
       "             898: [898, 2747, 4547],\n",
       "             899: [899, 1535, 2367, 2616],\n",
       "             900: [900],\n",
       "             901: [901, 2651, 3484, 4516],\n",
       "             902: [902],\n",
       "             903: [903, 7824],\n",
       "             904: [904],\n",
       "             905: [905, 2651, 4324],\n",
       "             906: [906, 1642],\n",
       "             907: [907, 1675],\n",
       "             908: [908, 4824, 8127],\n",
       "             909: [909, 8601],\n",
       "             910: [910],\n",
       "             911: [911],\n",
       "             912: [912, 2569],\n",
       "             913: [913, 7503],\n",
       "             914: [914, 2605],\n",
       "             915: [915],\n",
       "             916: [916],\n",
       "             917: [917],\n",
       "             918: [918, 2605, 2614, 2643, 2713],\n",
       "             919: [919, 3321],\n",
       "             920: [920, 3793],\n",
       "             921: [921, 3839],\n",
       "             922: [922],\n",
       "             923: [923],\n",
       "             924: [924, 3911],\n",
       "             925: [925],\n",
       "             926: [926, 4893],\n",
       "             927: [927, 3380],\n",
       "             928: [928],\n",
       "             929: [929],\n",
       "             930: [930, 2020],\n",
       "             931: [931],\n",
       "             932: [932, 7664, 8097],\n",
       "             933: [933, 2616, 2747, 3392],\n",
       "             934: [934, 1501, 2002, 2003],\n",
       "             935: [935, 1567, 8077],\n",
       "             936: [936],\n",
       "             937: [937, 2809],\n",
       "             938: [938, 2584, 3380, 8077],\n",
       "             939: [939, 3864, 4620],\n",
       "             940: [940, 5536],\n",
       "             941: [941],\n",
       "             942: [942, 7672, 8078],\n",
       "             943: [943, 1753, 1996, 2747],\n",
       "             944: [944],\n",
       "             945: [945, 2078, 3662],\n",
       "             946: [946, 7504],\n",
       "             947: [947, 2083],\n",
       "             948: [948, 1721],\n",
       "             949: [949],\n",
       "             950: [950, 7668, 8535],\n",
       "             951: [951, 8084],\n",
       "             952: [952],\n",
       "             953: [953],\n",
       "             954: [954, 2118],\n",
       "             955: [955],\n",
       "             956: [956, 2118],\n",
       "             957: [957, 1592, 2655],\n",
       "             958: [958, 1494, 2625, 7516],\n",
       "             959: [959, 7526, 7533],\n",
       "             960: [960],\n",
       "             961: [961, 1508],\n",
       "             962: [962, 2787],\n",
       "             963: [963],\n",
       "             964: [964],\n",
       "             965: [965, 3342],\n",
       "             966: [966],\n",
       "             967: [967, 1675, 2779, 4077, 4165],\n",
       "             968: [968],\n",
       "             969: [969, 3392, 4447, 4470, 7806],\n",
       "             970: [970],\n",
       "             971: [971, 2189],\n",
       "             972: [972],\n",
       "             973: [973, 4324],\n",
       "             974: [974],\n",
       "             975: [975, 2809, 3864],\n",
       "             976: [976],\n",
       "             977: [977, 2577, 2793, 8292],\n",
       "             978: [978, 1567, 3484],\n",
       "             979: [979],\n",
       "             980: [980, 7594],\n",
       "             981: [981, 8601],\n",
       "             982: [982],\n",
       "             983: [983, 6793],\n",
       "             984: [984],\n",
       "             985: [985],\n",
       "             986: [986, 2809, 4532],\n",
       "             987: [987, 3793, 4547, 4873],\n",
       "             988: [988],\n",
       "             989: [989, 7681],\n",
       "             990: [990],\n",
       "             991: [991],\n",
       "             992: [992, 3256],\n",
       "             993: [993, 5746],\n",
       "             994: [994],\n",
       "             995: [995, 2584],\n",
       "             996: [996, 8704],\n",
       "             997: [997, 8704],\n",
       "             998: [998],\n",
       "             999: [999, 8363],\n",
       "             ...})"
      ]
     },
     "execution_count": 285,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "adj"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 276,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "9105"
      ]
     },
     "execution_count": 276,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(adj)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 286,
   "metadata": {},
   "outputs": [],
   "source": [
    "#将邻接矩阵转为csr矩阵存储\n",
    "adj = nx.adjacency_matrix(nx.from_dict_of_lists(adj))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 287,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<9105x9105 sparse matrix of type '<class 'numpy.int64'>'\n",
       "\twith 24063 stored elements in Compressed Sparse Row format>"
      ]
     },
     "execution_count": 287,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "adj"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 288,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([ True,  True,  True, ..., False, False, False])"
      ]
     },
     "execution_count": 288,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "train_mask"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 291,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([0.00149701, 0.00149701, 0.00149701, ..., 0.00453858, 0.00100857,\n",
       "       0.00050429])"
      ]
     },
     "execution_count": 291,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "features[1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 292,
   "metadata": {},
   "outputs": [],
   "source": [
    "def preprocess_adj(adj):\n",
    "    \"\"\"Preprocessing of adjacency matrix for scGCN model and conversion to tuple representation.\"\"\"\n",
    "    adj_normalized = normalize_adj(adj + sp.eye(adj.shape[0]))\n",
    "    return sparse_to_tuple(adj_normalized)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 294,
   "metadata": {},
   "outputs": [],
   "source": [
    "#归一化邻接矩阵\n",
    "def normalize_adj(adj):\n",
    "    \"\"\"Symmetrically normalize adjacency matrix.\"\"\"\n",
    "    adj = sp.coo_matrix(adj)\n",
    "    rowsum = np.array(adj.sum(1))\n",
    "    d_inv_sqrt = np.power(rowsum, -0.5).flatten()\n",
    "    d_inv_sqrt[np.isinf(d_inv_sqrt)] = 0.\n",
    "    d_mat_inv_sqrt = sp.diags(d_inv_sqrt)\n",
    "    return adj.dot(d_mat_inv_sqrt).transpose().dot(d_mat_inv_sqrt).tocoo()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 开始分析train.py 代码"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 295,
   "metadata": {},
   "outputs": [],
   "source": [
    "#归一化邻接矩阵\n",
    "support = [preprocess_adj(adj)]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 296,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[(array([[   0,    0],\n",
       "         [   1,    1],\n",
       "         [   2,    2],\n",
       "         ...,\n",
       "         [3057, 9104],\n",
       "         [4554, 9104],\n",
       "         [9104, 9104]], dtype=int32),\n",
       "  array([1.        , 1.        , 1.        , ..., 0.12598816, 0.15430335,\n",
       "         0.28571429]),\n",
       "  (9105, 9105))]"
      ]
     },
     "execution_count": 296,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "support"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 299,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([1.        , 1.        , 1.        , ..., 0.12598816, 0.15430335,\n",
       "       0.28571429])"
      ]
     },
     "execution_count": 299,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "support[0][1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 300,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "24063"
      ]
     },
     "execution_count": 300,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(support[0][1])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 302,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(array([[   0, 1997],\n",
       "        [   0, 1990],\n",
       "        [   0, 1989],\n",
       "        ...,\n",
       "        [9104,   11],\n",
       "        [9104,    1],\n",
       "        [9104,    0]], dtype=int32),\n",
       " array([0.00149701, 0.00149701, 0.00149701, ..., 0.00453858, 0.00100857,\n",
       "        0.00050429]),\n",
       " (9105, 2000))"
      ]
     },
     "execution_count": 302,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "features"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 303,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2000"
      ]
     },
     "execution_count": 303,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "features[2][1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 304,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(9105, 2000)"
      ]
     },
     "execution_count": 304,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "features[2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 305,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[1., 0., 0., ..., 0., 0., 0.],\n",
       "       [1., 0., 0., ..., 0., 0., 0.],\n",
       "       [1., 0., 0., ..., 0., 0., 0.],\n",
       "       ...,\n",
       "       [0., 0., 0., ..., 0., 0., 0.],\n",
       "       [0., 0., 0., ..., 0., 0., 0.],\n",
       "       [0., 0., 0., ..., 0., 0., 0.]])"
      ]
     },
     "execution_count": 305,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "labels_binary_train"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 306,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[1., 0., 0., ..., 0., 0., 0.],\n",
       "       [1., 0., 0., ..., 0., 0., 0.],\n",
       "       [1., 0., 0., ..., 0., 0., 0.],\n",
       "       ...,\n",
       "       [0., 0., 0., ..., 0., 0., 1.],\n",
       "       [0., 0., 0., ..., 0., 0., 1.],\n",
       "       [0., 0., 0., ..., 0., 0., 1.]])"
      ]
     },
     "execution_count": 306,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#稠密矩阵标签\n",
    "new_label"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 307,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "8"
      ]
     },
     "execution_count": 307,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "labels_binary_train.shape[1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Define placeholders\n",
    "placeholders = {\n",
    "    'support':#存放邻接矩阵\n",
    "    [tf.sparse_placeholder(tf.float32) for _ in range(num_supports)],\n",
    "    'features':#存放基因矩阵\n",
    "    tf.sparse_placeholder(tf.float32,\n",
    "                          shape=tf.constant(features[2], dtype=tf.int64)),\n",
    "    'labels':#存放训练集、测试集、验证集标签\n",
    "    tf.placeholder(tf.float32, shape=(None, labels_binary_train.shape[1])),\n",
    "    'labels_mask':#存放mask标记标签\n",
    "    tf.placeholder(tf.int32),\n",
    "    'dropout':#防止过拟合，随机设置为0，提供泛化能力\n",
    "    tf.placeholder_with_default(0., shape=()),\n",
    "    'num_features_nonzero':#存放基因中的非0数目\n",
    "    tf.placeholder(tf.int32)  # helper variable for sparse dropout\n",
    "}\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 308,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2000"
      ]
     },
     "execution_count": 308,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "features[2][1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Create model 创建模型，输入的维度2000维\n",
    "model = model_func(placeholders, input_dim=features[2][1], logging=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 309,
   "metadata": {},
   "outputs": [],
   "source": [
    "#评估模型\n",
    "#观察在训练过程中分类器在训练集和验证集上的准确率\n",
    "# Define model evaluation function\n",
    "def evaluate(features, support, labels, mask, placeholders):\n",
    "    t_test = time.time()\n",
    "    feed_dict_val = construct_feed_dict(features, support, labels, mask,\n",
    "                                        placeholders)\n",
    "    outs_val = sess.run([model.loss, model.accuracy], feed_dict=feed_dict_val)\n",
    "    return outs_val[0], outs_val[1], (time.time() - t_test)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Initialize session\n",
    "sess = tf.Session()\n",
    "# Init variables\n",
    "sess.run(tf.global_variables_initializer())\n",
    "\n",
    "train_accuracy = []\n",
    "train_loss = []\n",
    "val_accuracy = []\n",
    "val_loss = []\n",
    "test_accuracy = []\n",
    "test_loss = []"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#训练模型\n",
    "# Train model\n",
    "#configurate checkpoint directory to save intermediate model training weights\n",
    "saver = tf.train.Saver()\n",
    "save_dir = 'checkpoints/'\n",
    "if not os.path.exists(save_dir):\n",
    "    os.makedirs(save_dir)\n",
    "\n",
    "save_path = os.path.join(save_dir, 'best_validation')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "for epoch in range(FLAGS.epochs):\n",
    "    t = time.time()\n",
    "    # Construct feed dictionary 构建装载数据字典features 2000维单细胞基因数据，support邻接矩阵数据\n",
    "    feed_dict = construct_feed_dict(features, support, labels_binary_train,\n",
    "                                    train_mask, placeholders)\n",
    "    feed_dict.update({placeholders['dropout']: FLAGS.dropout})\n",
    "    # Training step\n",
    "    outs = sess.run([model.opt_op, model.loss, model.accuracy],\n",
    "                    feed_dict=feed_dict)\n",
    "    train_accuracy.append(outs[2])\n",
    "    train_loss.append(outs[1])\n",
    "    # Validation\n",
    "    cost, acc, duration = evaluate(features, support, labels_binary_val,\n",
    "                                   val_mask, placeholders)\n",
    "    val_loss.append(cost)\n",
    "    val_accuracy.append(acc)\n",
    "    test_cost, test_acc, test_duration = evaluate(features, support,\n",
    "                                                  labels_binary_test,\n",
    "                                                  test_mask, placeholders)\n",
    "    test_accuracy.append(test_acc)\n",
    "    test_loss.append(test_cost)\n",
    "    saver.save(sess=sess, save_path=save_path)\n",
    "    print(\"Epoch:\", '%04d' % (epoch + 1), \"train_loss=\",\n",
    "          \"{:.5f}\".format(outs[1]), \"train_acc=\", \"{:.5f}\".format(outs[2]),\n",
    "          \"val_loss=\", \"{:.5f}\".format(cost), \"val_acc=\", \"{:.5f}\".format(acc),\n",
    "          \"time=\", \"{:.5f}\".format(time.time() - t))\n",
    "    if epoch > FLAGS.early_stopping and val_loss[-1] > np.mean(\n",
    "            val_loss[-(FLAGS.early_stopping + 1):-1]):\n",
    "        print(\"Early stopping...\")\n",
    "        break"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 311,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "9105"
      ]
     },
     "execution_count": 311,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(train_mask)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 310,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([ True,  True,  True, ...,  True,  True,  True])"
      ]
     },
     "execution_count": 310,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#'  outputs \n",
    "all_mask = np.array([True] * len(train_mask))\n",
    "all_mask"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 312,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[1., 0., 0., ..., 0., 0., 0.],\n",
       "       [1., 0., 0., ..., 0., 0., 0.],\n",
       "       [1., 0., 0., ..., 0., 0., 0.],\n",
       "       ...,\n",
       "       [0., 0., 0., ..., 0., 0., 1.],\n",
       "       [0., 0., 0., ..., 0., 0., 1.],\n",
       "       [0., 0., 0., ..., 0., 0., 1.]])"
      ]
     },
     "execution_count": 312,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "labels_binary_all = new_label\n",
    "labels_binary_all"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#' accuracy on all masks\n",
    "# 一个样本Y的标签 y=[0,0,0,1,0]，也就是说样本Y的真实标签是4，假设模型预测的结果概率（softmax的输出）p=[0.1,0.15,0.05,0.6,0.1]，可以看出这个预测是对的\n",
    "ab = sess.run(tf.nn.softmax(predict_output))\n",
    "#判断预测输出的值和标签的值是相等，ab是softmax概率\n",
    "#all_prediction 如果预测值和标签值一样为True，否则为False\n",
    "all_prediction = sess.run(\n",
    "    tf.equal(sess.run(tf.argmax(ab, 1)),\n",
    "             sess.run(tf.argmax(labels_binary_all, 1))))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#' accuracy on prediction masks \n",
    "# 统计预测的值和真实值的比例\n",
    "acc_train = np.sum(all_prediction[train_mask]) / np.sum(train_mask)\n",
    "acc_test = np.sum(all_prediction[test_mask]) / np.sum(test_mask)\n",
    "acc_val = np.sum(all_prediction[val_mask]) / np.sum(val_mask)\n",
    "acc_pred = np.sum(all_prediction[pred_mask]) / np.sum(pred_mask)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 313,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>0</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>alpha</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>alpha</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>alpha</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>alpha</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>alpha</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9100</th>\n",
       "      <td>quiescent_stellate</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9101</th>\n",
       "      <td>quiescent_stellate</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9102</th>\n",
       "      <td>quiescent_stellate</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9103</th>\n",
       "      <td>quiescent_stellate</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9104</th>\n",
       "      <td>quiescent_stellate</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>9105 rows × 1 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                       0\n",
       "0                  alpha\n",
       "1                  alpha\n",
       "2                  alpha\n",
       "3                  alpha\n",
       "4                  alpha\n",
       "...                  ...\n",
       "9100  quiescent_stellate\n",
       "9101  quiescent_stellate\n",
       "9102  quiescent_stellate\n",
       "9103  quiescent_stellate\n",
       "9104  quiescent_stellate\n",
       "\n",
       "[9105 rows x 1 columns]"
      ]
     },
     "execution_count": 313,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "true_label"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 314,
   "metadata": {},
   "outputs": [],
   "source": [
    "scGCN_all_labels = true_label.values.flatten()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 315,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array(['alpha', 'alpha', 'alpha', ..., 'quiescent_stellate',\n",
       "       'quiescent_stellate', 'quiescent_stellate'], dtype=object)"
      ]
     },
     "execution_count": 315,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "scGCN_all_labels"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 316,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([False, False, False, ..., False, False, False])"
      ]
     },
     "execution_count": 316,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pred_mask"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "class scGCN(Model):\n",
    "    def __init__(self, placeholders, input_dim, **kwargs):\n",
    "        super(scGCN, self).__init__(**kwargs)\n",
    "\n",
    "        self.inputs = placeholders['features']\n",
    "        self.input_dim = input_dim\n",
    "        # self.input_dim = self.inputs.get_shape().as_list()[1]  # To be supported in future Tensorflow versions\n",
    "        self.output_dim = placeholders['labels'].get_shape().as_list()[1]\n",
    "        self.placeholders = placeholders\n",
    "        #Adam 算法利用梯度的一阶矩估计和二阶矩估计动态调整每个参数的学习率。\n",
    "        #TensorFlow提供的tf.train.AdamOptimizer可控制学习速度，经过偏置校正后，每一次迭代学习率都有个确定范围，使得参数比较平稳。\n",
    "        self.optimizer = tf.train.AdamOptimizer(learning_rate=FLAGS.learning_rate)\n",
    "\n",
    "        self.build()\n",
    "\n",
    "    def _loss(self):\n",
    "        # Weight decay loss\n",
    "        for var in self.layers[0].vars.values():\n",
    "            self.loss += FLAGS.weight_decay * tf.nn.l2_loss(var)\n",
    "\n",
    "        # Cross entropy error\n",
    "        self.loss += masked_softmax_cross_entropy(self.outputs, self.placeholders['labels'],\n",
    "                                                  self.placeholders['labels_mask'])\n",
    "\n",
    "    def _accuracy(self):\n",
    "        self.accuracy = masked_accuracy(self.outputs, self.placeholders['labels'],\n",
    "                                        self.placeholders['labels_mask'])\n",
    "\n",
    "    def _build(self):\n",
    "\n",
    "        self.layers.append(GraphConvolution(input_dim=self.input_dim,\n",
    "                                            output_dim=FLAGS.hidden1,\n",
    "                                            placeholders=self.placeholders,\n",
    "                                            act=tf.nn.relu,\n",
    "                                            dropout=True,\n",
    "                                            sparse_inputs=True,\n",
    "                                            logging=self.logging))\n",
    "\n",
    "        self.layers.append(GraphConvolution(input_dim=FLAGS.hidden1,\n",
    "                                            output_dim=self.output_dim,\n",
    "                                            placeholders=self.placeholders,\n",
    "                                            act=lambda x: x,\n",
    "                                            dropout=True,\n",
    "                                            logging=self.logging))\n",
    "\n",
    "    def predict(self):\n",
    "        return tf.nn.softmax(self.outputs)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
